Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/docker-emulator-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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<<EOF" >> $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
Expand All @@ -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 }}
3 changes: 2 additions & 1 deletion packages/emulators-docker/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ app
seed_data/*
# retain latest tar file
!seed_data/pp-2022-12-04.tar.gz
exports
exports
build.args
Binary file not shown.
3 changes: 3 additions & 0 deletions packages/emulators-docker/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -24,4 +26,5 @@ export const PATHS = {
dockerFile,
functionsDistIndex,
seedDataDir,
buildArgsFile,
}
13 changes: 12 additions & 1 deletion packages/emulators-docker/src/prepare.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}

Expand Down