diff --git a/.github/workflows/docker-emulator-build.yml b/.github/workflows/docker-emulator-build.yml index 6a45a8d303..f8748ba321 100644 --- a/.github/workflows/docker-emulator-build.yml +++ b/.github/workflows/docker-emulator-build.yml @@ -14,6 +14,8 @@ on: - closed branches: - master + # Only create new build when seed data or functions update + # Ignore src-only changes as will populate conflicting docker image tag paths: - 'packages/emulators-docker/seed_data/**' # Allow manual trigger of build in case of broken/minor updates @@ -55,7 +57,7 @@ jobs: with: images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }},${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} tags: | - type=raw,value=2022-10-30 + type=raw,value=2022-12-04 # TODO - would be nice to extract tags based on seed data provided automatically or consider other strategies # https://github.com/docker/metadata-action#tags-input flavor: | @@ -80,6 +82,14 @@ jobs: run: export REACT_APP_PROJECT_VERSION=${GITHUB_SHA} - name: Prepare Build run: yarn workspace oa-emulators-docker prepare + # Populate the list of build args generated in the prepare script to local env as multi line string + # https://docs.github.com/en/github-ae@latest/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + - name: Set build args + run: | + BUILD_ARGS=$(cat packages/emulators-docker/build.args) + echo "BUILD_ARGS<> $GITHUB_ENV + echo "$BUILD_ARGS" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV # Build and deploy # This will use the tags generate to identify target destination, by default pushing to both @@ -94,3 +104,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }}, mode=max + # Ensure args pass as multiline string + build-args: | + ${{ env.BUILD_ARGS }} diff --git a/packages/emulators-docker/.gitignore b/packages/emulators-docker/.gitignore index d7205f9ac1..810b36ad96 100644 --- a/packages/emulators-docker/.gitignore +++ b/packages/emulators-docker/.gitignore @@ -3,4 +3,5 @@ app seed_data/* # retain latest tar file !seed_data/pp-2022-12-04.tar.gz -exports \ No newline at end of file +exports +build.args \ No newline at end of file diff --git a/packages/emulators-docker/seed_data/pp-2022-10-30.tar.gz b/packages/emulators-docker/seed_data/pp-2022-10-30.tar.gz deleted file mode 100644 index db46ae50be..0000000000 Binary files a/packages/emulators-docker/seed_data/pp-2022-10-30.tar.gz and /dev/null differ diff --git a/packages/emulators-docker/src/paths.ts b/packages/emulators-docker/src/paths.ts index 7d5975d698..ec3d7d6467 100644 --- a/packages/emulators-docker/src/paths.ts +++ b/packages/emulators-docker/src/paths.ts @@ -10,6 +10,8 @@ const dockerFile = path.resolve(workspaceDir, 'Dockerfile') const seedDataDir = path.resolve(workspaceDir, 'seed_data') +const buildArgsFile = path.resolve(workspaceDir, 'build.args') + const functionsDistIndex = path.resolve( rootDir, 'functions', @@ -24,4 +26,5 @@ export const PATHS = { dockerFile, functionsDistIndex, seedDataDir, + buildArgsFile, } diff --git a/packages/emulators-docker/src/prepare.ts b/packages/emulators-docker/src/prepare.ts index 00330be3c4..e1ba4aeafb 100644 --- a/packages/emulators-docker/src/prepare.ts +++ b/packages/emulators-docker/src/prepare.ts @@ -1,4 +1,4 @@ -import { spawnSync } from 'child_process' +import { execSync, spawnSync } from 'child_process' import chalk from 'chalk' import fs from 'fs-extra' import { runtimeConfigTest } from 'functions/scripts/runtimeConfig/model' @@ -220,6 +220,17 @@ function generateBuildArgs() { const functionsPackageJson = fs.readJsonSync(functionsPackageJsonPath) buildArgs.FIREBASE_TOOLS_VERSION = functionsPackageJson.dependencies['firebase-tools'] + // assign date and git commit sha ref + buildArgs.BUILD_DATE = new Date().toISOString() + buildArgs.VCS_REF = execSync('git rev-parse HEAD').toString().trim() + // write args to file to read from dockerfile ci + fs.writeFileSync( + PATHS.buildArgsFile, + Object.entries(buildArgs) + .map(([k, v]) => `${k}=${v}`) + .join('\n'), + ) + console.table(buildArgs) return buildArgs }