-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (100 loc) · 3.49 KB
/
Copy pathdocker.yml
File metadata and controls
110 lines (100 loc) · 3.49 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Docker
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
paths:
- 'src/**'
- 'Dockerfile'
- 'package.json'
- 'bun.lock'
- '.github/workflows/docker.yml'
workflow_run:
workflows: ["CI"]
types:
- completed
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
if: >-
github.event_name != 'workflow_run' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main')
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout latest tag if triggered by workflow_run
if: github.event_name == 'workflow_run'
run: |
# Get the latest tag and checkout to it
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LATEST_TAG" ]; then
echo "Checking out latest tag: $LATEST_TAG"
git checkout "$LATEST_TAG"
else
echo "No tags found, staying on main"
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version context
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_run" ]; then
# Get the latest tag when triggered by workflow_run
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LATEST_TAG" ]; then
echo "Using tag context: $LATEST_TAG"
echo "version=${LATEST_TAG#v}" >> $GITHUB_OUTPUT
echo "is_tag=true" >> $GITHUB_OUTPUT
else
echo "No tag found, using main context"
echo "version=main" >> $GITHUB_OUTPUT
echo "is_tag=false" >> $GITHUB_OUTPUT
fi
else
echo "Using default context"
echo "is_tag=false" >> $GITHUB_OUTPUT
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}},value=${{ steps.version.outputs.version }},enable=${{ steps.version.outputs.is_tag == 'true' }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.version }},enable=${{ steps.version.outputs.is_tag == 'true' }}
type=semver,pattern={{major}},value=${{ steps.version.outputs.version }},enable=${{ steps.version.outputs.is_tag == 'true' }}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max