From 0b7d378a18baadab053431256ec49fb52c231be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ux=C3=ADo?= Date: Thu, 16 Nov 2023 22:45:48 +0100 Subject: [PATCH] Revert Dockerfile optimization (#2817) - As environment variables are picked during build phase, we need to revert the dockerfile until we find a solution (it's better that the image takes 30 minutes to run that it doesn't work) - Build docker image for ARM64. That should make Apple computers run the image faster --- .github/workflows/deploy-dockerhub.yml | 55 +++++++++++++++++++------- Dockerfile | 35 ++++++---------- scripts/github/deploy_docker.sh | 24 ----------- 3 files changed, 51 insertions(+), 63 deletions(-) delete mode 100644 scripts/github/deploy_docker.sh diff --git a/.github/workflows/deploy-dockerhub.yml b/.github/workflows/deploy-dockerhub.yml index db4c810127..a565ca8779 100644 --- a/.github/workflows/deploy-dockerhub.yml +++ b/.github/workflows/deploy-dockerhub.yml @@ -13,25 +13,50 @@ on: jobs: dockerhub-push: runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || (github.event_name == 'release' && github.event.action == 'released') steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + - uses: docker/setup-buildx-action@v3 - name: Dockerhub login - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Deploy Dockerhub main + - name: Deploy Main if: github.ref == 'refs/heads/main' - run: bash scripts/github/deploy_docker.sh staging - env: - DOCKERHUB_PROJECT: ${{ secrets.DOCKER_PROJECT }} - - name: Deploy Dockerhub dev + uses: docker/build-push-action@v5 + with: + push: true + tags: safeglobal/safe-wallet-web:staging + platforms: | + linux/amd64 + linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Deploy Develop if: github.ref == 'refs/heads/dev' - run: bash scripts/github/deploy_docker.sh dev - env: - DOCKERHUB_PROJECT: ${{ secrets.DOCKER_PROJECT }} - - name: Deploy Dockerhub tag - if: startsWith(github.ref, 'refs/tags/') - run: bash scripts/github/deploy_docker.sh ${GITHUB_REF##*/} - env: - DOCKERHUB_PROJECT: ${{ secrets.DOCKER_PROJECT }} + uses: docker/build-push-action@v5 + with: + push: true + tags: safeglobal/safe-wallet-web:dev + platforms: | + linux/amd64 + linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Deploy Tag + if: (github.event_name == 'release' && github.event.action == 'released') + uses: docker/build-push-action@v5 + with: + push: true + tags: | + safeglobal/safe-wallet-web:${{ github.event.release.tag_name }} + safeglobal/safe-wallet-web:latest + platforms: | + linux/amd64 + linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 9e8cba5245..82391964d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,21 @@ -FROM node:18-alpine AS base -ENV NEXT_TELEMETRY_DISABLED 1 - -FROM base AS builder - +FROM node:18-alpine RUN apk add --no-cache libc6-compat git python3 py3-pip make g++ libusb-dev eudev-dev linux-headers WORKDIR /app - -# Install dependencies -COPY package.json yarn.lock* ./ -RUN yarn --frozen-lockfile COPY . . -RUN yarn run after-install -RUN yarn build - -# Production image -FROM base AS runner -WORKDIR /app +# install deps +RUN yarn install --frozen-lockfile +RUN yarn after-install ENV NODE_ENV production -ENV REVERSE_PROXY_UI_PORT 8080 -RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs -COPY --from=builder /app/out ./out - -# Set the correct permission for prerender cache -RUN mkdir .next && chown nextjs:nodejs .next +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +# Uncomment the following line in case you want to disable telemetry during the build. +ENV NEXT_TELEMETRY_DISABLED 1 -USER nextjs +EXPOSE 3000 -EXPOSE ${REVERSE_PROXY_UI_PORT} +ENV PORT 3000 -CMD npx -y serve out -p ${REVERSE_PROXY_UI_PORT} +CMD ["yarn", "static-serve"] diff --git a/scripts/github/deploy_docker.sh b/scripts/github/deploy_docker.sh deleted file mode 100644 index 832a4878e5..0000000000 --- a/scripts/github/deploy_docker.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -export DOCKER_BUILDKIT=1 - -if [ "$1" = "dev" -o "$1" = "main" ]; then - # If image does not exist, don't use cache - docker pull safeglobal/$DOCKERHUB_PROJECT:$1 && \ - docker build -t $DOCKERHUB_PROJECT . --cache-from safeglobal/$DOCKERHUB_PROJECT:$1 --build-arg BUILDKIT_INLINE_CACHE=1 || \ - docker build -t $DOCKERHUB_PROJECT . --build-arg BUILDKIT_INLINE_CACHE=1 -else - # Building tag version from staging image (vX.X.X) - docker pull safeglobal/$DOCKERHUB_PROJECT:staging && \ - docker build -t $DOCKERHUB_PROJECT . --cache-from safeglobal/$DOCKERHUB_PROJECT:staging --build-arg BUILDKIT_INLINE_CACHE=1 || \ - docker build -t $DOCKERHUB_PROJECT . --build-arg BUILDKIT_INLINE_CACHE=1 - # Only push latest on release - case $1 in v*) - docker tag $DOCKERHUB_PROJECT safeglobal/$DOCKERHUB_PROJECT:latest - docker push safeglobal/$DOCKERHUB_PROJECT:latest - esac -fi -docker tag $DOCKERHUB_PROJECT safeglobal/$DOCKERHUB_PROJECT:$1 -docker push safeglobal/$DOCKERHUB_PROJECT:$1