-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (141 loc) · 6.27 KB
/
frontend-docker.yml
File metadata and controls
168 lines (141 loc) · 6.27 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
name: Frontend Docker Build
on:
push:
branches: [main]
paths:
- 'lib/**'
- 'web/**'
- 'assets/**'
- 'pubspec.yaml'
- 'Dockerfile'
- '.github/workflows/frontend-docker.yml'
pull_request:
branches: [main]
paths:
- 'lib/**'
- 'web/**'
- 'assets/**'
- 'pubspec.yaml'
permissions:
contents: write
packages: write
env:
IMAGE_NAME: tellmemo-frontend
jobs:
build-and-push:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: version
run: |
# Get the latest frontend tag or start at 0.0.0
LATEST_TAG=$(git tag -l "frontend-v*" --sort=-v:refname | head -1 | sed 's/frontend-v//' || echo "0.0.0")
# Increment patch version
IFS='.' read -ra VER <<< "$LATEST_TAG"
MAJOR=${VER[0]:-0}
MINOR=${VER[1]:-0}
PATCH=${VER[2]:-0}
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Building frontend version: $NEW_VERSION"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Setup configuration
run: |
# Update config.dart for Docker environment with specified values
# Set API Backend URL to Docker backend service
sed -i "s|static const String apiBaseUrl = '.*'|static const String apiBaseUrl = 'http://localhost:8000'|g" lib/config.dart
# Set environment to development
sed -i "s|static const String environment = '.*'|static const String environment = 'development'|g" lib/config.dart
# Set authentication provider to backend
sed -i "s|static const String authProvider = '.*'|static const String authProvider = 'backend'|g" lib/config.dart
# Enable logging
sed -i "s|static const bool enableLogging = [^;]*;|static const bool enableLogging = true;|g" lib/config.dart
# Disable debug mode
sed -i "s|static const bool enableDebugMode = [^;]*;|static const bool enableDebugMode = false;|g" lib/config.dart
# Disable Sentry
sed -i "s|static const bool sentryEnabled = [^;]*;|static const bool sentryEnabled = false;|g" lib/config.dart
# Clear Sentry DSN (handle multiline const)
perl -i -0pe "s/static const String sentryDsn =\s*\n?\s*'[^']*';/static const String sentryDsn = '';/g" lib/config.dart
# Disable Firebase Analytics (handle multiline const)
perl -i -0pe 's/static const bool firebaseAnalyticsEnabled =\s*\n?\s*[^;]*;/static const bool firebaseAnalyticsEnabled = false;/g' lib/config.dart
# Clear Supabase URL
sed -i "s|static const String supabaseUrl = '.*'|static const String supabaseUrl = ''|g" lib/config.dart
# Clear Supabase Anon Key
sed -i "s|static const String supabaseAnonKey = '.*'|static const String supabaseAnonKey = ''|g" lib/config.dart
echo "Configuration updated for Docker environment"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
# Configuration is baked into the image from lib/config.dart
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'develop' }}
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create git tag
uses: actions/github-script@v7
with:
script: |
const tagName = 'refs/tags/frontend-v${{ steps.version.outputs.version }}';
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tagName,
sha: context.sha
});
console.log(`Created tag: ${tagName}`);
} catch (error) {
if (error.status === 422) {
console.log(`Tag ${tagName} already exists, skipping creation`);
} else {
throw error;
}
}
- name: Create GitHub Release
uses: actions/github-script@v7
with:
script: |
const tagName = `frontend-v${{ steps.version.outputs.version }}`;
const releaseName = `Frontend v${{ steps.version.outputs.version }}`;
const branch = '${{ github.ref }}' === 'refs/heads/main' ? 'main' : 'develop';
const version = '${{ steps.version.outputs.version }}';
const sha = '${{ github.sha }}';
const dockerUsername = '${{ secrets.DOCKER_USERNAME }}';
const imageName = '${{ env.IMAGE_NAME }}';
const commitMessage = `${{ github.event.head_commit.message }}`.replace(/`/g, '\\`').replace(/\$/g, '\\$');
const bodyText = '## Frontend Release v' + version + '\n\n' +
'Branch: ' + branch + '\n' +
'Commit: ' + sha + '\n\n' +
'Docker Images:\n' +
'- `' + dockerUsername + '/' + imageName + ':' + version + '`\n' +
'- `' + dockerUsername + '/' + imageName + ':' + (branch === 'main' ? 'latest' : 'develop') + '`\n' +
'- `' + dockerUsername + '/' + imageName + ':' + sha + '`\n\n' +
'Changes:\n' + commitMessage;
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: releaseName,
body: bodyText,
draft: false,
prerelease: branch !== 'main'
});