Repository navigation
175 lines (157 loc) · 5.76 KB
/
Copy pathcd-development.yml
File metadata and controls
175 lines (157 loc) · 5.76 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: CD - Development Build
# Publish :develop (and sha tags) on demand only.
# Merges into develop no longer trigger an image publish — use workflow_dispatch
# when you intentionally want a fresh :develop image (e.g. before a demo or RC cut).
# Smoke tests must pass before push unless force_build=true.
on:
workflow_dispatch:
inputs:
force_build:
description: 'Force build even if tests fail'
required: false
type: boolean
default: false
concurrency:
group: dev-build-${{ github.ref }}
# Finish in-flight publishes so :develop reaches the registry; newer runs queue.
cancel-in-progress: false
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKERHUB_IMAGE: drytrix/timetracker
PYTHON_VERSION: '3.11'
jobs:
quick-tests:
name: Quick Test Suite
runs-on: ubuntu-latest
timeout-minutes: 20
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_PASSWORD: test_password
POSTGRES_USER: test_user
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-python-env
- name: Run smoke tests
env:
PYTHONPATH: ${{ github.workspace }}
DATABASE_URL: postgresql+psycopg2://test_user:test_password@localhost:5432/test_db
FLASK_ENV: testing
run: pytest -m smoke -v --tb=short --no-cov -n auto
build-and-push:
name: Build and Push Development Image
runs-on: ubuntu-latest
needs: quick-tests
if: always() && (needs.quick-tests.result == 'success' || github.event.inputs.force_build == 'true')
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase image name
id: image-name
run: |
IMAGE_NAME_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME_LOWER=${IMAGE_NAME_LOWER}" >> $GITHUB_OUTPUT
- name: Check Docker Hub credentials
id: dockerhub
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
if [ -n "$DOCKERHUB_USERNAME" ] && { [ -n "$DOCKERHUB_TOKEN" ] || [ -n "$DOCKERHUB_PASSWORD" ]; }; then
echo "enabled=true" >> $GITHUB_OUTPUT
else
echo "enabled=false" >> $GITHUB_OUTPUT
fi
- name: Log in to Docker Hub
if: steps.dockerhub.outputs.enabled == 'true'
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN || secrets.DOCKERHUB_PASSWORD }}
- name: Set image list for metadata
id: image-list
run: |
IMAGES="${{ steps.image-name.outputs.IMAGE_NAME_LOWER }}"
if [ "${{ steps.dockerhub.outputs.enabled }}" = "true" ]; then
IMAGES="${IMAGES}"$'\n'"${{ env.DOCKERHUB_IMAGE }}"
fi
{
echo "images<<EOF"
echo "$IMAGES"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.image-list.outputs.images }}
tags: |
type=raw,value=develop
type=raw,value=dev-{{date 'YYYYMMDD-HHmmss'}}
type=sha,prefix=dev-,format=short
labels: |
org.opencontainers.image.description=Self-hosted time tracking web application for projects, clients, and reports.
- name: Determine version
id: version
run: |
VERSION="dev-${{ github.run_number }}-${GITHUB_SHA::8}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Inject donate-hide public key (optional)
env:
DONATE_HIDE_PUBLIC_KEY_PEM: ${{ secrets.DONATE_HIDE_PUBLIC_KEY_PEM }}
run: |
if [ -n "$DONATE_HIDE_PUBLIC_KEY_PEM" ]; then
echo "$DONATE_HIDE_PUBLIC_KEY_PEM" > donate_hide_public.pem
fi
- name: Build and push Docker image
uses: docker/build-push-action@v7.4.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
run: |
{
echo "## Development image"
echo ""
echo "- Version: \`${{ steps.version.outputs.version }}\`"
echo "- Tags: \`develop\`, \`dev-<sha>\`"
echo "- GHCR: \`${{ steps.image-name.outputs.IMAGE_NAME_LOWER }}:develop\`"
if [ "${{ steps.dockerhub.outputs.enabled }}" = "true" ]; then
echo "- Docker Hub: \`${{ env.DOCKERHUB_IMAGE }}:develop\`"
else
echo "- Docker Hub: skipped (credentials not configured)"
fi
echo ""
echo "Publish is manual only (workflow_dispatch). Merges into \`develop\` do not build this image."
} >> "$GITHUB_STEP_SUMMARY"