Skip to content

GHA: Build and Publish to Public ECR and Build Nix #12

GHA: Build and Publish to Public ECR and Build Nix

GHA: Build and Publish to Public ECR and Build Nix #12

Workflow file for this run

name: Build and Push
# Builds and pushes the branch to ECR from master, or the manually selected branch when invoked manually. We stopped using Docker Hub for storing the image of oplogtoredis, where we used a Webhook to do the same thing.
on:
push:
branches:
- master
# Left this here in-case the workflow needs to be developed further rapidly:
pull_request:
types: [ opened, synchronize, reopened ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
permissions:
id-token: write # for the creds itself
contents: read # for checkout
jobs:
build-and-push:
name: Build and Push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-unstable
# Examples of the generated tags:
# - v3.0.0 (branch: master)
# - v3.0.0-branch-name (branch: branch-name)
- name: Generate Tag
id: generate-tag
run: |
# Extract the current version from `default.nix`. This must pass.
version=$(nix flake show . --quiet --all-systems --json | jq -r '.defaultPackage."aarch64-darwin".name' | cut -d'-' -f2-)
# Adds the branch name if the workflow is manually invoked from a branch.
tag_branch_segment=""
branch_name=${{ github.event.pull_request && github.head_ref || github.ref_name }}
if [ "$branch_name" != "master" ]; then
tag_branch_segment="-${branch_name}" # adds a -<branch-name> as needed
fi
tag="v${version}${tag_branch_segment}"
echo "TAG=${tag}" >> $GITHUB_OUTPUT
- name: Setup ECR/buildx
uses: ./.github/actions/setup-ecr-buildx
id: setup-ecr-buildx
with:
role-to-assume: ${{ secrets.AWS_PUBLIC_ECR_ROLE_ARN }}
registry-type: public
- name: Build and push image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # 4.0.0
with:
tags: ${{ steps.setup-ecr-buildx.outputs.ecr_registry }}/ecr-public/docker/tulip/oplogtoredis:${{ steps.generate-tag.outputs.TAG }}
provenance: false
push: true