-
-
Notifications
You must be signed in to change notification settings - Fork 5
142 lines (128 loc) · 5.41 KB
/
docker-publish.yml
File metadata and controls
142 lines (128 loc) · 5.41 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Build and Publish Docker Images
on:
push:
branches:
- main
- feature/creality-support
tags:
- 'v*'
env:
REGISTRY_GITHUB: ghcr.io
REGISTRY_DOCKERHUB: docker.io
IMAGE_NAME_APP: spoolmansync
IMAGE_NAME_HA: spoolmansync-homeassistant
IMAGE_NAME_ADDON: spoolmansync-addon
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Verify addon version matches package.json
if: startsWith(github.ref, 'refs/tags/v')
run: |
APP_VERSION=$(node -p "require('./app/package.json').version")
ADDON_VERSION=$(grep '^version:' spoolmansync-ha-addon/config.yaml | sed 's/version: *"\(.*\)"/\1/')
if [ "$APP_VERSION" != "$ADDON_VERSION" ]; then
echo "::error::Version mismatch! package.json=$APP_VERSION, config.yaml=$ADDON_VERSION"
exit 1
fi
echo "Versions match: $APP_VERSION"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_DOCKERHUB }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Generate tags based on trigger type
- name: Generate Docker tags for app
id: meta-app
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GITHUB }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME_APP }}
${{ env.REGISTRY_DOCKERHUB }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_APP }}
tags: |
# Set latest tag for main branch and version tags
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
# Set version tag (v1.0.0 -> 1.0.0)
type=semver,pattern={{version}}
# Set major.minor tag (v1.0.0 -> 1.0)
type=semver,pattern={{major}}.{{minor}}
# Beta tag for feature branches
type=raw,value=creality-beta,enable=${{ github.ref == 'refs/heads/feature/creality-support' }}
- name: Generate Docker tags for HA
id: meta-ha
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GITHUB }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME_HA }}
${{ env.REGISTRY_DOCKERHUB }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_HA }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=creality-beta,enable=${{ github.ref == 'refs/heads/feature/creality-support' }}
- name: Generate Docker tags for addon
id: meta-addon
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GITHUB }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME_ADDON }}
${{ env.REGISTRY_DOCKERHUB }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_ADDON }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=creality-beta,enable=${{ github.ref == 'refs/heads/feature/creality-support' }}
# Build and push main app image (multi-arch: amd64 + arm64)
- name: Build and push SpoolmanSync app
uses: docker/build-push-action@v6
with:
context: ./app
file: ./app/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-app.outputs.tags }}
labels: ${{ steps.meta-app.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Build and push Home Assistant image (multi-arch: amd64 + arm64)
- name: Build and push SpoolmanSync Home Assistant
uses: docker/build-push-action@v6
with:
context: ./homeassistant
file: ./homeassistant/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-ha.outputs.tags }}
labels: ${{ steps.meta-ha.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Build and push HA add-on image (multi-arch: amd64 + arm64)
# Context is repo root since Dockerfile needs both app/ and spoolmansync-ha-addon/rootfs/
- name: Build and push SpoolmanSync Add-on
uses: docker/build-push-action@v6
with:
context: .
file: ./spoolmansync-ha-addon/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-addon.outputs.tags }}
labels: ${{ steps.meta-addon.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max