-
Notifications
You must be signed in to change notification settings - Fork 37
133 lines (114 loc) · 4.66 KB
/
docker-image.yml
File metadata and controls
133 lines (114 loc) · 4.66 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
name: Build and Push Multi-Platform Docker Image
on:
# Build on releases (recommended for production)
release:
types: [published]
# Also allow develop branch for testing
push:
branches:
- develop # Dev builds → :develop
paths-ignore:
- 'CHANGELOG.md'
- '*.md'
# Allow manual trigger
workflow_dispatch:
inputs:
tag:
description: 'Docker tag (e.g., v1.5.0 or latest)'
required: true
default: 'manual'
include_latest:
description: 'Also tag as latest'
required: false
default: false
type: boolean
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
- name: Install dependencies
run: npm install
- name: Create config file
run: |
if [ ! -f config/config.json ]; then
cp config/config.json.example config/config.json
fi
- name: Run tests
run: npm test
env:
NODE_ENV: test
build:
runs-on: ubuntu-latest
needs: test # Only run if tests pass
steps:
- name: Checkout the repository
uses: actions/checkout@v4.1.7
- name: Docker Setup QEMU
uses: docker/setup-qemu-action@v3.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.6.1
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
- name: Determine Docker tags
id: docker_tags
run: |
SHORT_SHA="${GITHUB_SHA::7}"
if [ "${{ github.event_name }}" = "release" ]; then
# Release: tag with version and latest
VERSION="${{ github.event.release.tag_name }}"
# Remove 'v' prefix if present for semver tag
SEMVER="${VERSION#v}"
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/slackonos:latest,${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${VERSION},${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${SEMVER}" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "github_ref=refs/tags/${VERSION}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual trigger
TAG="${{ github.event.inputs.tag }}"
if [ "${{ github.event.inputs.include_latest }}" = "true" ]; then
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/slackonos:latest,${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${TAG},${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${TAG}-${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
echo "github_ref=refs/tags/${TAG}" >> $GITHUB_OUTPUT
else
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${TAG},${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${TAG}-${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
echo "github_ref=" >> $GITHUB_OUTPUT
fi
else
# Develop branch
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/slackonos:develop,${{ secrets.DOCKERHUB_USERNAME }}/slackonos:develop-${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
echo "github_ref=" >> $GITHUB_OUTPUT
fi
- name: Build and push multi-platform Docker image
uses: docker/build-push-action@v6.7.0
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.docker_tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
GITHUB_REF=${{ steps.docker_tags.outputs.github_ref }}
- name: Verify the platforms
run: docker buildx inspect --bootstrap
- name: Create GitHub Release Summary
if: github.event_name == 'release'
run: |
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ github.event.release.tag_name }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Pull commands:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/slackonos:latest" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/slackonos:${{ github.event.release.tag_name }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY