Skip to content

Commit 619df04

Browse files
committed
feat(ci): add GitHub Actions workflow for Docker image build and push
This commit introduces a new GitHub Actions workflow to automate the building and pushing of Docker images. The workflow triggers on pushes and pull requests to the main branch, specifically when changes are made to the Dockerfile or the workflow file itself. It uses GitHub's Container Registry for storing images and supports multi-platform builds for amd64 and arm64 architectures.
1 parent 4b7ffc8 commit 619df04

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/docker-build.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docker/Dockerfile.base'
9+
- '.github/workflows/docker-build.yml'
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- 'docker/Dockerfile.base'
15+
- '.github/workflows/docker-build.yml'
16+
workflow_dispatch:
17+
18+
env:
19+
REGISTRY: ghcr.io
20+
IMAGE_NAME: ${{ github.repository }}/base
21+
22+
jobs:
23+
build-and-push:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Log in to Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=sha,prefix={{branch}}-
49+
type=raw,value=latest,enable={{is_default_branch}}
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
file: ./docker/Dockerfile.base
59+
push: true
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
platforms: linux/amd64,linux/arm64

0 commit comments

Comments
 (0)