Add Github Actions with Buildx for Docker publish

This commit is contained in:
ShahanaFarooqui 2024-06-24 22:24:09 -07:00
parent d51929a4b7
commit a8c00f1ae7
4 changed files with 59 additions and 110 deletions

53
.github/workflows/docker-release.yml vendored Normal file
View File

@ -0,0 +1,53 @@
name: Build docker images
on:
push:
tags:
- '^v[0-9]{2}\.[0-9]{2}(\.[0-9]{1,2})?$'
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up version
id: set-version
run: |
if [ "${{ github.event.inputs.version }}" != "" ]; then
VERSION=${{ github.event.inputs.version }}
elif [ "${{ github.ref_type }}" == "tag" ]; then
VERSION=${{ github.ref_name }}
else
echo "No version provided and no tag found."
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
shahanafarooqui/rtl:${{ env.VERSION }}

View File

@ -1,7 +1,6 @@
# ---------------
# Install Dependencies
# ---------------
FROM node:18-alpine as builder
ARG BASE_DISTRO="node:alpine"
FROM --platform=${BUILDPLATFORM} ${BASE_DISTRO} as builder
WORKDIR /RTL
@ -10,9 +9,6 @@ COPY package-lock.json /RTL/package-lock.json
RUN npm install --legacy-peer-deps
# ---------------
# Build App
# ---------------
COPY . .
# Build the Angular application
@ -24,15 +20,12 @@ RUN npm run buildbackend
# Remove non production necessary modules
RUN npm prune --omit=dev --legacy-peer-deps
# ---------------
# Release App
# ---------------
FROM node:18-alpine as runner
WORKDIR /RTL
FROM --platform=$BUILDPLATFORM ${BASE_DISTRO} as runner
RUN apk add --no-cache tini
WORKDIR /RTL
COPY --from=builder /RTL/rtl.js ./rtl.js
COPY --from=builder /RTL/package.json ./package.json
COPY --from=builder /RTL/frontend ./frontend

View File

@ -1,49 +0,0 @@
# ---------------
# Install Dependencies
# ---------------
FROM node:18-alpine as builder
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-armel /tini
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-armel.asc /tini.asc
RUN chmod +x /tini
WORKDIR /RTL
COPY package.json /RTL/package.json
COPY package-lock.json /RTL/package-lock.json
RUN npm install --legacy-peer-deps
# ---------------
# Build App
# ---------------
COPY . .
# Build the Angular application
RUN npm run buildfrontend
# Build the Backend from typescript server
RUN npm run buildbackend
# Remove non production necessary modules
RUN npm prune --omit=dev --legacy-peer-deps
# ---------------
# Release App
# ---------------
FROM arm32v7/node:18-alpine as runner
WORKDIR /RTL
COPY --from=builder /RTL/rtl.js ./rtl.js
COPY --from=builder /RTL/package.json ./package.json
COPY --from=builder /RTL/frontend ./frontend
COPY --from=builder /RTL/backend ./backend
COPY --from=builder /RTL/node_modules/ ./node_modules
COPY --from=builder "/tini" /sbin/tini
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["node", "rtl"]

View File

@ -1,48 +0,0 @@
# ---------------
# Install Dependencies
# ---------------
FROM node:18-alpine as builder
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-arm64 /tini
RUN chmod +x /tini
WORKDIR /RTL
COPY package.json /RTL/package.json
COPY package-lock.json /RTL/package-lock.json
RUN npm install --legacy-peer-deps
# ---------------
# Build App
# ---------------
COPY . .
# Build the Angular application
RUN npm run buildfrontend
# Build the Backend from typescript server
RUN npm run buildbackend
# Remove non production necessary modules
RUN npm prune --omit=dev --legacy-peer-deps
# ---------------
# Release App
# ---------------
FROM arm64v8/node:18-alpine as runner
WORKDIR /RTL
COPY --from=builder /RTL/rtl.js ./rtl.js
COPY --from=builder /RTL/package.json ./package.json
COPY --from=builder /RTL/frontend ./frontend
COPY --from=builder /RTL/backend ./backend
COPY --from=builder /RTL/node_modules/ ./node_modules
COPY --from=builder "/tini" /sbin/tini
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["node", "rtl"]