-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (47 loc) · 1.66 KB
/
docker-build-push.yaml
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
# .github/workflows/docker-publish.yml
name: Build and Publish Docker
on:
push:
branches:
- main
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Add release tag
id: release_tag
run: |
if [[ ${{ github.ref }} == refs/tags/* ]]; then
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Set version arg
id: version_tag
run: |
if [[ ${{ github.ref }} == refs/heads/main ]]; then
echo "VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
fi
- name: docker build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
build-args: |
VERSION=${{ steps.version_tag.outputs.VERSION }}
tags: |
ghcr.io/${{ github.repository }}:${{ steps.version_tag.outputs.VERSION }}
${{ steps.release_tag.outputs.RELEASE_VERSION != '' && 'ghcr.io/${{ github.repository }}:${{ steps.release_tag.outputs.RELEASE_VERSION }}' || '' }}
${{ steps.release_tag.outputs.RELEASE_VERSION != '' && 'ghcr.io/${{ github.repository }}:latest' || '' }}
platforms: ${{ matrix.platform }}