Updating Circle CI config to move to Buildx setup (#1419)

This commit is contained in:
ShahanaFarooqui 2024-06-24 18:04:20 -07:00 committed by GitHub
parent 125a3b61ae
commit f92e1473ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 168 additions and 223 deletions

View File

@ -1,102 +1,59 @@
version: 2
version: 2.1
executors:
docker-executor:
docker:
- image: circleci/python:3.8
jobs:
# Define in CircleCi Project Variables: $DOCKERHUB_REPO, $DOCKERHUB_USER, $DOCKERHUB_PASS
# Publish jobs require those variables
publish_docker_linuxamd64:
machine:
docker_layer_caching: false
setup-docker-buildx:
executor: docker-executor
steps:
- checkout
- setup_remote_docker:
version: 20.10.7
experimental: true
- run:
name: Set up QEMU
command: |
LATEST_TAG="${CIRCLE_TAG:1}"
DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG-amd64"
DOCKERHUB_DOCKERFILE="dockerfiles/Dockerfile"
sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS
sudo docker build --pull -t "$DOCKERHUB_DESTINATION" -f "$DOCKERHUB_DOCKERFILE" .
sudo docker push "$DOCKERHUB_DESTINATION"
no_output_timeout: 25m
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- run:
name: Set up Buildx
command: |
docker buildx create --use
docker buildx inspect --bootstrap
publish_docker_linuxarm32v7:
machine:
docker_layer_caching: false
publish_docker:
executor: docker-executor
steps:
- checkout
- setup_remote_docker:
version: 20.10.7
experimental: true
- checkout
- run:
name: Set up QEMU
command: |
sudo docker run --rm --privileged multiarch/qemu-user-static:register --reset
LATEST_TAG="${CIRCLE_TAG:1}"
DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG-arm32v7"
DOCKERHUB_DOCKERFILE="dockerfiles/Dockerfile.arm32v7"
sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS
sudo docker build --pull -t "$DOCKERHUB_DESTINATION" -f "$DOCKERHUB_DOCKERFILE" .
sudo docker push "$DOCKERHUB_DESTINATION"
no_output_timeout: 25m
publish_docker_linuxarm64v8:
machine:
docker_layer_caching: false
steps:
- checkout
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- run:
name: Set up Buildx
command: |
sudo docker run --rm --privileged multiarch/qemu-user-static:register --reset
LATEST_TAG="${CIRCLE_TAG:1}"
DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG-arm64v8"
DOCKERHUB_DOCKERFILE="dockerfiles/Dockerfile.arm64v8"
sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS
sudo docker build --pull -t "$DOCKERHUB_DESTINATION" -f "$DOCKERHUB_DOCKERFILE" .
sudo docker push "$DOCKERHUB_DESTINATION"
no_output_timeout: 25m
publish_docker_multiarch:
machine:
enabled: true
image: ubuntu-2004:2022.07.1
steps:
docker buildx create --use
docker buildx inspect --bootstrap
- run:
name: Build and push Docker images
command: |
# Turn on Experimental features
LATEST_TAG="${CIRCLE_TAG:1}"
sudo mkdir ./.docker
sudo sh -c 'echo "{ \"experimental\": \"enabled\" }" >> ./.docker/config.json'
#
sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS
#
sudo docker manifest create --amend "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-amd64" "$DOCKERHUB_REPO:$LATEST_TAG-arm32v7" "$DOCKERHUB_REPO:$LATEST_TAG-arm64v8"
sudo docker manifest annotate "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-amd64" --os linux --arch amd64
sudo docker manifest annotate "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-arm32v7" --os linux --arch arm --variant v7
sudo docker manifest annotate "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-arm64v8" --os linux --arch arm64 --variant v8
sudo docker manifest push "$DOCKERHUB_REPO:$LATEST_TAG" -p
no_output_timeout: 25m
DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG"
docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS
docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --pull -t "$DOCKERHUB_DESTINATION" -f dockerfiles/Dockerfile --push .
workflows:
version: 2
publish:
jobs:
- publish_docker_linuxamd64:
filters:
branches:
ignore: /.*/
tags:
only: /v(?:(?<major>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<minor>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<patch>(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?:([A-Za-z1-9])*))?)$/
- publish_docker_linuxarm32v7:
filters:
branches:
ignore: /.*/
tags:
only: /v(?:(?<major>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<minor>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<patch>(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?:([A-Za-z1-9])*))?)$/
- publish_docker_linuxarm64v8:
filters:
branches:
ignore: /.*/
tags:
only: /v(?:(?<major>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<minor>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<patch>(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?:([A-Za-z1-9])*))?)$/
- publish_docker_multiarch:
- setup-docker-buildx
- publish_docker:
requires:
- publish_docker_linuxamd64
- publish_docker_linuxarm32v7
- publish_docker_linuxarm64v8
- setup-docker-buildx
filters:
branches:
ignore: /.*/

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:$VERSION

78
Dockerfile Normal file
View File

@ -0,0 +1,78 @@
FROM node:18-alpine as base
WORKDIR /RTL
COPY package.json /RTL/package.json
COPY package-lock.json /RTL/package-lock.json
RUN npm install --legacy-peer-deps
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
FROM arm32v7/node:18-alpine as runner-arm32v7
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 --from=base /RTL/rtl.js ./rtl.js
COPY --from=base /RTL/package.json ./package.json
COPY --from=base /RTL/frontend ./frontend
COPY --from=base /RTL/backend ./backend
COPY --from=base /RTL/node_modules/ ./node_modules
COPY --from=base /tini /sbin/tini
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["node", "rtl"]
FROM arm64v8/node:18-alpine as runner-arm64v8
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-arm64 /tini
RUN chmod +x /tini
WORKDIR /RTL
COPY --from=base /RTL/rtl.js ./rtl.js
COPY --from=base /RTL/package.json ./package.json
COPY --from=base /RTL/frontend ./frontend
COPY --from=base /RTL/backend ./backend
COPY --from=base /RTL/node_modules/ ./node_modules
COPY --from=base /tini /sbin/tini
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["node", "rtl"]
FROM node:18-alpine as runner-amd64
RUN apk add --no-cache tini
WORKDIR /RTL
COPY --from=base /RTL/rtl.js ./rtl.js
COPY --from=base /RTL/package.json ./package.json
COPY --from=base /RTL/frontend ./frontend
COPY --from=base /RTL/backend ./backend
COPY --from=base /RTL/node_modules/ ./node_modules
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["node", "rtl"]

View File

@ -1,46 +0,0 @@
# ---------------
# Install Dependencies
# ---------------
FROM node:18-alpine as builder
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 node:18-alpine as runner
WORKDIR /RTL
RUN apk add --no-cache tini
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
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["node", "rtl"]

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"]