From 67fda6f2e25c383cc6601d5ca5a598162d5af77b Mon Sep 17 00:00:00 2001 From: Rob Kooper Date: Fri, 24 May 2024 15:50:56 -0400 Subject: [PATCH 1/2] update docker workflow (#798) * update docker workflow * update actions * optimize build, fix warning * use node 16 * always push * cache and push --- .github/workflows/ci.yaml | 12 ++-- .github/workflows/docker.yaml | 112 ++++++++++++++++++---------------- Dockerfile | 3 +- 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b44c51195..a41ed0c17 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,6 +6,8 @@ on: - main - staging - expt + tags: + - "v*.*.*" pull_request: jobs: @@ -13,17 +15,17 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '14.x' + node-version: '16.x' - name: Get yarn cache directory path id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index a97338a24..457ace201 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -15,6 +15,8 @@ on: - main - staging - expt + tags: + - "v*.*.*" pull_request: # Certain actions will only run when this is the main repo. @@ -26,65 +28,69 @@ jobs: docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - # calculate some variables that are used later - - name: github branch + # create metadata for image + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + ${{ env.DOCKERHUB_ORG }}/frontend + ghcr.io/${{ github.repository_owner }}/frontend + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + # setup docker build + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Inspect Builder run: | - BRANCH=${GITHUB_REF##*/} - if [ "$BRANCH" == "main" ]; then - TAGS="latest,$(date +'%Y%m%d')" - else - TAGS="$BRANCH" - fi - TAGS="${TAGS},${BRANCH}-${{ github.run_number }}" - echo "TAGS=${TAGS}" >> $GITHUB_ENV - echo "GITHUB_BRANCH=${BRANCH}" >> $GITHUB_ENV + echo "Name: ${{ steps.buildx.outputs.name }}" + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" + echo "Status: ${{ steps.buildx.outputs.status }}" + echo "Flags: ${{ steps.buildx.outputs.flags }}" + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - # build the docker image, this will always run to make sure - # the Dockerfile still works. - - name: Build image - uses: elgohr/Publish-Docker-Github-Action@2.22 - env: - BRANCH: ${{ env.GITHUB_BRANCH }} - BUILDNUMBER: ${{ github.run_number }} - GITSHA1: ${{ github.sha }} + # login to registries + - name: Login to DockerHub + uses: docker/login-action@v3 with: - registry: docker.pkg.github.com - name: ${{ github.repository_owner }}/${{ github.event.repository.name }}/frontend - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - tags: "${{ env.TAGS }}" - buildargs: BRANCH,BUILDNUMBER,GITSHA1 - no_push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - # this will publish to github container registry - - name: Publish to GitHub - if: github.event_name == 'push' && github.repository == env.MAIN_REPO - uses: elgohr/Publish-Docker-Github-Action@2.22 - env: - BRANCH: ${{ env.GITHUB_BRANCH }} - BUILDNUMBER: ${{ github.run_number }} - GITSHA1: ${{ github.sha }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 with: registry: ghcr.io - name: ${{ github.repository_owner }}/frontend - username: ${{ secrets.GHCR_USERNAME }} - password: ${{ secrets.GHCR_PASSWORD }} - tags: "${{ env.TAGS }}" - buildargs: BRANCH,BUILDNUMBER,GITSHA1 + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - # this will publish to the classtranscribe dockerhub repo - - name: Publish to Docker Hub - if: github.event_name == 'push' && github.repository == env.MAIN_REPO - uses: elgohr/Publish-Docker-Github-Action@2.22 - env: - BRANCH: ${{ env.GITHUB_BRANCH }} - BUILDNUMBER: ${{ github.run_number }} - GITSHA1: ${{ github.sha }} + # build the docker images + - name: Build and push frontend + uses: docker/build-push-action@v5 with: - name: ${{ env.DOCKERHUB_ORG }}/frontend - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - tags: "${{ env.TAGS }}" - buildargs: BRANCH,BUILDNUMBER,GITSHA1 + context: . + #push: ${{ github.event_name != 'pull_request' }} + push: true + platforms: "linux/amd64,linux/arm64" + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=classtranscribe/frontend-pipeline:buildcache + cache-to: type=registry,ref=classtranscribe/frontend:buildcache,mode=max + build-args: | + BRANCH=${{ steps.meta.outputs.version }} + BUILDNUMBER=${{ github.run_number }} + ARG GITSHA1=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 3a3437fde..d35548509 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ # ---------------------------------------------------------------------- # COMPILE REACT APP # ---------------------------------------------------------------------- -FROM node:16 AS frontend - +FROM --platform=$BUILDPLATFORM node:16 AS frontend WORKDIR /frontend COPY package.json yarn.lock getDefaultConfig.js changeBackend.js /frontend/ From c8730aca6d2e00a53feed3faff1dfac71c220d0a Mon Sep 17 00:00:00 2001 From: Lawrence Angrave <4468456+angrave@users.noreply.github.com> Date: Sun, 2 Jun 2024 12:38:56 -0500 Subject: [PATCH 2/2] Update ci.yaml add" run tests" --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a41ed0c17..02da19c80 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -47,6 +47,9 @@ jobs: run: | yarn lint:quiet + - name: Run tests + run: yarn test + - name: Compile application env: CI: false