From 2662a16f6edd3078de8879c94b3904bffec9fa5f Mon Sep 17 00:00:00 2001 From: Adam Saturna Date: Mon, 29 May 2023 08:42:30 -0600 Subject: [PATCH] #1966 Adding Github Action for publishing multi-arch docker images on DockerHub Github action that triggers docker image build and publish action upon: * merging into master using tag :master * creating a new Prism Release with tags: latest, , Additionally adding YARN_NETWORK_TIMEOUT to Dockerfile with default value set to Yarn's default. This extra argument increases network timeout for arm64 Docker image builds since QEMU emulation tends to be slow. --- .github/workflows/dockerhub-publish.yml | 63 +++++++++++++++++++++++++ Dockerfile | 8 +++- 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/dockerhub-publish.yml diff --git a/.github/workflows/dockerhub-publish.yml b/.github/workflows/dockerhub-publish.yml new file mode 100644 index 000000000..39522d5da --- /dev/null +++ b/.github/workflows/dockerhub-publish.yml @@ -0,0 +1,63 @@ +name: Build & Publish Docker image + +on: + push: + branches: + - master + release: + types: [published] + +env: + IS_RELEASE: ${{github.event_name == 'release'}} + DOCKER_BUILD_ARGS: | + BUILD_TYPE=production + YARN_NETWORK_TIMEOUT=480000 + DOCKER_BUILD_PLATFORMS: | + linux/amd64 + linux/arm64 + +jobs: + docker-publish: + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Compute release version tags + if: env.IS_RELEASE == 'true' + run: | + echo "TAG_PRIMARY_VERSION=$(release='${{github.event.release.tag_name}}' && echo ${release:1:1})" >> $GITHUB_ENV + echo "TAG_FULL_VERSION=$(release='${{github.event.release.tag_name}}' && echo ${release:1})" >> $GITHUB_ENV + - + name: Build and Push release tags + if: env.IS_RELEASE == 'true' + uses: docker/build-push-action@v4 + with: + push: true + tags: | + ${{format('{0}/prism:{1}', secrets.DOCKERHUB_USERNAME, env.TAG_FULL_VERSION)}} + ${{format('{0}/prism:{1}', secrets.DOCKERHUB_USERNAME, env.TAG_PRIMARY_VERSION)}} + ${{format('{0}/prism:{1}', secrets.DOCKERHUB_USERNAME, 'latest')}} + platforms: ${{env.DOCKER_BUILD_PLATFORMS}} + build-args: ${{env.DOCKER_BUILD_ARGS}} + - + name: Build and Push master Tag + if: env.IS_RELEASE != 'true' + uses: docker/build-push-action@v4 + with: + push: true + tags: | + ${{format('{0}/prism:master', secrets.DOCKERHUB_USERNAME)}} + platforms: ${{env.DOCKER_BUILD_PLATFORMS}} + build-args: ${{env.DOCKER_BUILD_ARGS}} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 453597ba6..9c4683056 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,19 @@ FROM node:16 as compiler +ARG YARN_NETWORK_TIMEOUT=30000 + WORKDIR /usr/src/prism COPY package.json yarn.lock /usr/src/prism/ COPY packages/ /usr/src/prism/packages/ -RUN yarn && yarn build +RUN yarn --network-timeout $YARN_NETWORK_TIMEOUT && yarn build ############################################################### FROM node:16 as dependencies +ARG YARN_NETWORK_TIMEOUT=30000 + WORKDIR /usr/src/prism/ COPY package.json /usr/src/prism/ @@ -28,7 +32,7 @@ COPY packages/cli/package.json /usr/src/prism/packages/cli/ RUN mkdir -p /usr/src/prism/packages/cli/node_modules ENV NODE_ENV production -RUN yarn --production +RUN yarn --network-timeout $YARN_NETWORK_TIMEOUT --production RUN if [ $(uname -m) != "aarch64" ]; then curl -sfL https://gobinaries.com/tj/node-prune | bash; fi RUN if [ $(uname -m) != "aarch64" ]; then node-prune; fi