-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (62 loc) · 2.07 KB
/
build-docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Build and Push Docker Images
on:
push:
tags:
- '*'
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
REGISTRY: docker.io
USERNAME: ${{ secrets.DOCKER_USERNAME }}
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get the latest tag
id: get-tag
run: |
TAG=$(git describe --tags --abbrev=0)
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Extract image name from tag message
id: extract-image-name
run: |
TAG_MESSAGE=$(git tag -l --format='%(contents)' ${{ env.TAG }})
if [[ "$TAG_MESSAGE" =~ build\/([^ ]+) ]]; then
IMAGE_NAME=${BASH_REMATCH[1]}
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
else
echo "No valid image name specified in tag message."
exit 1
fi
- name: Verify Dockerfile exists
run: |
if [ ! -f "$IMAGE_NAME/Dockerfile" ]; then
echo "Dockerfile not found in the specified directory: $IMAGE_NAME"
exit 1
fi
- uses: docker/setup-qemu-action@v2
with:
platforms: amd64
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
file: ${{ env.IMAGE_NAME }}/Dockerfile
context: .
platforms: linux/amd64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}