-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (59 loc) · 3 KB
/
build-and-push-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Build and push container image to GHCR
# Run this workflow whenever a Release is published.
on:
release:
types: [published]
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Sychronize `VERSION` file with Git tag
# Get the Git tag name (e.g. "v1.2.3") associated with the GitHub Release,
# strip away the leading "v", and write the remainder to the `VERSION` file.
#
# Note: If the Git tag name doesn't start with a "v" followed by a number,
# we just write the entire Git tag name to the `VERSION` file.
#
# Note: In bash, `[[ condition ]] && command1 || command2` is a form of if/then/else.
# Also, in bash, `${BASH_REMATCH[1]}` contains the first regex capture group.
#
run: |
TAG_NAME='${{ github.ref_name }}'
[[ "${TAG_NAME}" =~ ^v([0-9].*) ]] && VERSION="${BASH_REMATCH[1]}" || VERSION="${TAG_NAME}"
echo "${VERSION}" > ./VERSION
- name: Authenticate with container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Use the `docker/metadata-action` action to extract values that can
# be incorporated into the tags and labels of the resulting container
# image. The step's `id` ("meta") can be used in subsequent steps to
# reference the output of this step.
# For more info: https://github.com/docker/metadata-action
- name: Prepare metadata of container image
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/microbiomedata/nmdc-aggregator
flavor: latest=false
tags: type=semver,pattern={{version}}
# Use the `docker/build-push-action` action to build the image described
# by the `Dockerfile`. If the build succeeds, push the image to GHCR.
# It uses the `tags` and `labels` parameters to tag and label the image
# with the output from the "meta" step above.
# For more info: https://github.com/docker/build-push-action#usage.
- name: Build and push container image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# References:
# - https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
# - https://github.com/microbiomedata/nmdc-server/blob/main/.github/workflows/deploy.yml