Skip to content
Merged
73 changes: 40 additions & 33 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
name: Build Docker image and publish to ECR

# A push to main publishes latest-SNAPSHOT. To publish a release, dispatch on
# its tag once the tag exists:
#
# gh workflow run build_docker.yml --ref v<version> -f image_tag=release
#
# The release check fails the run unless the tag matches package.json and the
# version is new, and it moves latest only for the highest version. Start one
# release at a time: two runs started together can both pass the check before
# either pushes.

on:
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -27,27 +37,28 @@ concurrency:
jobs:
build-and-push-image:
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 20
env:
IS_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }}
# Where every step pushes and reads, including scripts/releaseImage.ts.
IMAGE: public.ecr.aws/neptune/graph-explorer

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Get package version
id: package-version
run: echo "version=$(node -p 'require("./package.json").version')" >> $GITHUB_OUTPUT
- name: Set up Node.js
if: ${{ env.IS_RELEASE == 'true' }}
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .node-version
package-manager-cache: false

- name: Get image tag
id: get-image-tag
env:
IS_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }}
VERSION: ${{ steps.package-version.outputs.version }}
run: |
if [ "$IS_RELEASE" = "true" ]; then
echo "image_tag=$VERSION" >> $GITHUB_OUTPUT
else
echo "image_tag=latest-SNAPSHOT" >> $GITHUB_OUTPUT
fi
# Runs before anything is pushed.
- name: Check the release and choose its tags
id: release
if: ${{ env.IS_RELEASE == 'true' }}
run: node scripts/releaseImage.ts plan

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
Expand All @@ -67,25 +78,21 @@ jobs:

- name: Build, tag, and push Docker image
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: neptune
REPOSITORY: graph-explorer
IMAGE_TAG: ${{ steps.get-image-tag.outputs.image_tag }}
# Snapshot runs skip the plan, so they push the snapshot tags.
TAGS: ${{ steps.release.outputs.tags || 'latest-SNAPSHOT sagemaker-latest-SNAPSHOT' }}
# TAGS is a space-separated list.
run: |
docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
docker tag $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-$IMAGE_TAG
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-$IMAGE_TAG
read -ra tags <<< "$TAGS"
docker build -t "$IMAGE:${tags[0]}" .
for tag in "${tags[@]}"; do
docker tag "$IMAGE:${tags[0]}" "$IMAGE:$tag"
docker push "$IMAGE:$tag"
done

- name: Update latest tag for release
if: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }}
- name: Check every pushed tag points to one image
if: ${{ env.IS_RELEASE == 'true' }}
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: neptune
REPOSITORY: graph-explorer
IMAGE_TAG: ${{ steps.get-image-tag.outputs.image_tag }}
TAGS: ${{ steps.release.outputs.tags }}
run: |
docker tag $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest
docker tag $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-latest
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-latest
read -ra tags <<< "$TAGS"
node scripts/releaseImage.ts verify "${tags[@]}"
Loading
Loading