Skip to content

Commit 700f9ac

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

File tree

3 files changed

+107
-45
lines changed

3 files changed

+107
-45
lines changed

.github/workflows/ci-docker.yaml

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,18 @@ 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 }}

.github/workflows/publish.yaml

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

.github/workflows/release.yaml

Lines changed: 40 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,18 @@ 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+
4585
release:
4686
name: Make release
4787
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)