-
Notifications
You must be signed in to change notification settings - Fork 261
65 lines (57 loc) · 1.98 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
name: build docker image
on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
jobs:
dockerize:
name: Build Docker image and push to GitHub Container Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- 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.GITHUB_TOKEN }}
- name: Set environment variables for docker build
run: |
# Lowercase repo for Github Container Registry
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
# Ensure tags are checked out
git fetch origin +refs/tags/*:refs/tags/*
# Version number from tag
echo "MINTPY_VERSION=$(git describe --tags)" >> $GITHUB_ENV
- name: Build, tag, and push image to Github Container Registry
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
ghcr.io/${{ env.REPO }}:${{ env.MINTPY_VERSION }}
labels: |
org.opencontainers.image.created=${{ env.CI_JOB_TIMESTAMP }}
org.opencontainers.image.version=${{ env.MINTPY_VERSION }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Add develop tag
if: github.ref == 'refs/heads/main'
uses: akhilerm/[email protected]
with:
src: ghcr.io/${{ env.REPO }}:${{ env.MINTPY_VERSION }}
dst: ghcr.io/${{ env.REPO }}:develop
- name: Add latest tag
if: startsWith(github.ref, 'refs/tags/v')
uses: akhilerm/[email protected]
with:
src: ghcr.io/${{ env.REPO }}:${{ env.MINTPY_VERSION }}
dst: ghcr.io/${{ env.REPO }}:latest