Skip to content

Commit 765ed02

Browse files
authored
Add GitHub Actions workflow for Docker image build
This workflow builds and pushes a Docker image to GitHub Container Registry on push and pull request events for the main branch. It also creates a release when a new version tag is pushed.
1 parent f1c242e commit 765ed02

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to Container Registry
32+
if: github.event_name != 'pull_request'
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+
tags: |
45+
type=ref,event=branch
46+
type=semver,pattern={{version}}
47+
type=semver,pattern={{major}}.{{minor}}
48+
type=sha
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v5
52+
with:
53+
context: .
54+
push: ${{ github.event_name != 'pull_request' }}
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max
59+
60+
- name: Create Release
61+
if: startsWith(github.ref, 'refs/tags/v')
62+
uses: softprops/action-gh-release@v1
63+
with:
64+
generate_release_notes: true
65+
body: |
66+
## Container Image
67+
- **Registry**: ${{ env.REGISTRY }}
68+
- **Image**: ${{ env.IMAGE_NAME }}
69+
- **Tag**: ${{ github.ref_name }}
70+
71+
### Contenu du container
72+
- ✓ Debian Bookworm Slim
73+
- ✓ htop (moniteur de processus)
74+
- ✓ zsh (shell)
75+
- ✓ curl, wget, git (outils utiles)

0 commit comments

Comments
 (0)