Skip to content

Commit 8d52123

Browse files
committed
fix: cicd to build image and push to the ghcr.io
1 parent 0a784d5 commit 8d52123

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

.github/workflows/docker-image.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Create and publish a Docker image
2+
3+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
4+
on:
5+
push:
6+
branches: [ "dev", "31-fix-cidi-pipeline"]
7+
pull_request_target:
8+
types:
9+
- closed
10+
branches: [ "main","dev" ]
11+
12+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
18+
jobs:
19+
build-and-push-image:
20+
if: github.event.pull_request.merged == true
21+
runs-on: ubuntu-latest
22+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
23+
permissions:
24+
contents: read
25+
packages: write
26+
attestations: write
27+
id-token: write
28+
29+
steps:
30+
# Check out branch
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
#js: read version
35+
- name: set VER
36+
run: echo "VER=$(awk -F \" '/version/ {print $2 }' pyproject.toml)" >> $GITHUB_ENV
37+
38+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
39+
- name: Log in to the Container registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
47+
- name: Extract metadata (tags, labels) for Docker
48+
id: meta
49+
uses: docker/metadata-action@v5
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
tags: |
53+
type=raw,value=latest,enable=${{ base_ref == 'main' }}
54+
type=semver,pattern={{version}},value=${{ env.VER }},enable=${{ base_ref == 'main' }}
55+
type=raw,value=dev,enable=${{ base_ref == 'dev' || branch == 'dev' }}
56+
type=raw,value=cicd-test,enable=${{ branch == '31-fix-cidi-pipeline' }}
57+
58+
# js: added in for multi arch building
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@v3
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
65+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
66+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
67+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
68+
- name: Build and push Docker image
69+
id: push
70+
uses: docker/build-push-action@v6
71+
with:
72+
platforms: linux/amd64,linux/arm64 #js: added for multi arch building
73+
context: .
74+
push: true
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}
77+
78+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
79+
- name: Generate artifact attestation
80+
uses: actions/attest-build-provenance@v2
81+
with:
82+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
83+
subject-digest: ${{ steps.push.outputs.digest }}
84+
push-to-registry: true

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Change log for the codebase. Initialised from the developments following version
3838
- fix: omic path parsing bug
3939
- fix: plotting bug arising from api change
4040
- fix: correct file permissions
41+
- fix: cicd to build image and push to the `ghcr.io`
4142

4243
### Security
4344

0 commit comments

Comments
 (0)