Skip to content

Commit da32a8c

Browse files
Eneman DonatienEneman Donatien
authored andcommitted
[CI] Build image docker on release
1 parent 8a0dcb3 commit da32a8c

File tree

3 files changed

+118
-45
lines changed

3 files changed

+118
-45
lines changed

.github/workflows/ci-docker.yaml

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,21 @@ jobs:
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
22-
- uses: hadolint/[email protected]
23-
with:
24-
dockerfile: Dockerfile
2522

26-
build-docker:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- name: Checkout code
30-
uses: actions/checkout@v4
3123

32-
- name: Docker meta
33-
id: docker_meta
34-
uses: docker/metadata-action@v5
35-
with:
36-
images: inseefrlab/s3-operator # list of Docker images to use as base name for tags
37-
tags: |
38-
type=ref,event=branch
39-
type=ref,event=pr
40-
type=semver,pattern={{version}}
41-
type=semver,pattern={{major}}.{{minor}}
42-
43-
- name: Set up QEMU
44-
uses: docker/setup-qemu-action@v3
45-
46-
- name: Set up Docker Buildx
47-
uses: docker/setup-buildx-action@v3
48-
49-
- name: Login to DockerHub
50-
if: github.event_name != 'pull_request'
51-
uses: docker/login-action@v3
52-
with:
53-
username: ${{ secrets.DOCKERHUB_USERNAME }}
54-
password: ${{ secrets.DOCKERHUB_TOKEN }}
55-
56-
- name: Build and push
57-
id: build_push
58-
uses: docker/build-push-action@v6
24+
- uses: hadolint/[email protected]
5925
with:
60-
context: .
61-
file: ./Dockerfile
62-
push: ${{ github.event_name != 'pull_request' }}
63-
# Use tags computed before
64-
tags: |
65-
${{ steps.docker_meta.outputs.tags }}
66-
labels: ${{ steps.docker_meta.outputs.labels }}
67-
platforms: linux/amd64,linux/arm64
26+
dockerfile: Dockerfile
6827

69-
- name: Image digest
70-
run: echo ${{ steps.build_push.outputs.digest }}
28+
build-and-publish-docker:
29+
needs: lint-docker
30+
uses: ./.github/workflows/publish.yaml
31+
permissions:
32+
id-token: write
33+
contents: read
34+
with:
35+
ref: ${{ github.ref }}
36+
image-tag: ${{ github.ref }}
37+
secrets:
38+
registry_username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
registry_password: ${{ secrets.DOCKERHUB_TOKEN }}

.github/workflows/publish.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Reusable workflow to publish docker image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
required: false
8+
default: main
9+
type: string
10+
image-tag:
11+
required: false
12+
type: string
13+
secrets:
14+
registry_username:
15+
required: true
16+
registry_password:
17+
required: true
18+
19+
jobs:
20+
build-and-publish-docker:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0 # Ensure full history
27+
ref: ${{ github.event.inputs.source_ref }}
28+
29+
- name: Docker meta
30+
id: docker_meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: inseefrlab/s3-operator # list of Docker images to use as base name for tags
34+
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Login to DockerHub
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@v3
44+
with:
45+
username: ${{ github.event.inputs.registry_username }}
46+
password: ${{ github.event.inputs.registry_password }}
47+
48+
- name: Build and push
49+
id: build_push
50+
uses: docker/build-push-action@v6
51+
with:
52+
context: .
53+
file: ./Dockerfile
54+
push: ${{ github.event_name != 'pull_request' }}
55+
tags: |
56+
${{ github.event.inputs.image-tag }}
57+
labels: ${{ steps.docker_meta.outputs.labels }}
58+
platforms: linux/amd64,linux/arm64
59+
60+
- name: Image digest
61+
run: echo ${{ steps.build_push.outputs.digest }}

.github/workflows/release.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,38 @@ on:
1515
default: false
1616
type: boolean
1717

18+
1819
name: Make release
1920

2021
jobs:
22+
23+
create-branch:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write # Allows pushing branches
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0 # Ensure full history
32+
ref: ${{ github.event.inputs.source_ref }}
33+
34+
- name: Configure Git
35+
run: |
36+
git config user.name "$GITHUB_ACTOR"
37+
git config user.email "[email protected]"
38+
39+
- name: Create and push new branch
40+
env:
41+
VERSION: ${{ github.event.inputs.version }}
42+
run: |
43+
NEW_BRANCH="release-${VERSION}"
44+
git checkout -b $NEW_BRANCH
45+
git push origin $NEW_BRANCH
46+
2147
tags:
2248
runs-on: ubuntu-latest
49+
needs: create-branch
2350
permissions:
2451
id-token: write
2552
contents: write
@@ -29,6 +56,7 @@ jobs:
2956
uses: actions/checkout@v4
3057
with:
3158
fetch-depth: 0
59+
ref: ${{ github.event.inputs.source_ref }}
3260

3361
- name: Configure Git
3462
run: |
@@ -42,6 +70,21 @@ jobs:
4270
git tag -f -a ${VERSION} -m "Release ${VERSION}."
4371
git push -f origin ${VERSION}
4472
73+
74+
build-and-publish-docker:
75+
needs:
76+
- tags
77+
uses: ./.github/workflows/publish.yaml
78+
permissions:
79+
id-token: write
80+
contents: read
81+
with:
82+
ref: ${{ github.ref }}
83+
image-tag: ${{ github.ref }}
84+
secrets:
85+
registry_username: ${{ secrets.DOCKERHUB_USERNAME }}
86+
registry_password: ${{ secrets.DOCKERHUB_TOKEN }}
87+
4588
release:
4689
name: Make release
4790
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)