forked from glauth/glauth
-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (172 loc) · 6.8 KB
/
docker-deploy.yml
File metadata and controls
200 lines (172 loc) · 6.8 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Release
on:
push:
tags:
- 'v*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-binaries:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpam0g-dev
- name: Install xgo for cross-compilation
run: |
go install src.techknowlogick.com/xgo@latest
- name: Build main binaries for all architectures
working-directory: ./v2
run: |
# Ensure all dependencies are properly downloaded and verified
GOWORK=off go mod download
GOWORK=off go mod verify
GOWORK=off go mod tidy
# Explicitly get the missing dependency that causes issues in xgo
GOWORK=off go get github.com/munnerz/goautoneg
GOWORK=off go get github.com/prometheus/common/expfmt@v0.65.0
# Update go.sum and mod files after adding dependencies
GOWORK=off go mod tidy
# List module status for debugging
echo "Go module status:"
GOWORK=off go list -m all | grep -E "(prometheus|munnerz)" || true
# Store the exact Go version and build flags
GO_RELEASE_V=$(go version | { read _ _ v _; echo ${v#go}; })
echo "GO_VERSION=$GO_RELEASE_V" >> $GITHUB_ENV
echo "BUILD_LDFLAGS=-s -w" >> $GITHUB_ENV
echo "XGO_IMAGE=techknowlogick/xgo:latest" >> $GITHUB_ENV
# Build main binaries using xgo with embedded database support
# Database handlers are now embedded, no separate plugins needed
xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out glauth -dest bin \
-targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64,windows/amd64,windows/386" \
-env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct,GOWORK=off" .
# Fix ownership and permissions for files created by xgo (which runs as root in docker)
sudo chown -R $USER:$USER bin/ 2>/dev/null || true
chmod -R 755 bin/ 2>/dev/null || true
# Create sha256 files for each binary
cd bin
for binary in glauth-*; do
if [[ -f "$binary" ]]; then
echo "Creating sha256 for $binary"
sha256sum "$binary" > "$binary.sha256"
fi
done
- name: List all built artifacts
working-directory: ./v2/bin
run: |
echo "Built artifacts:"
ls -la
echo ""
echo "SHA256 files:"
ls -la *.sha256 2>/dev/null || echo "No SHA256 files found yet"
# Ensure all files have proper permissions and ownership
sudo chown -R runner:runner . 2>/dev/null || true
chmod -R 644 *.sha256 2>/dev/null || true
chmod -R 755 glauth-* 2>/dev/null || true
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-artifacts
path: v2/bin/
build-docker-and-release:
needs: build-binaries
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: release-artifacts
path: v2/bin/
- name: Extract tag name
id: tag
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Prepare Docker assets
working-directory: ./v2
run: |
# Create platform-specific directories for Docker build
mkdir -p docker/assets/linux/amd64 docker/assets/linux/arm64 docker/assets/linux/arm/v7
# Copy binaries with embedded database support
if [[ -f "bin/glauth-linux-amd64" ]]; then
cp bin/glauth-linux-amd64 docker/assets/linux/amd64/glauth
chmod +x docker/assets/linux/amd64/glauth
fi
if [[ -f "bin/glauth-linux-arm64" ]]; then
cp bin/glauth-linux-arm64 docker/assets/linux/arm64/glauth
chmod +x docker/assets/linux/arm64/glauth
fi
if [[ -f "bin/glauth-linux-arm-7" ]]; then
cp bin/glauth-linux-arm-7 docker/assets/linux/arm/v7/glauth
chmod +x docker/assets/linux/arm/v7/glauth
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.title=GLAuth
org.opencontainers.image.description=A simple LDAP server for development, home use, or CI pipelines with embedded database support
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.licenses=MIT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./v2/docker
file: ./v2/docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: List available files for release
working-directory: ./v2/bin
run: |
echo "Files available for release:"
ls -la
echo ""
echo "Main binaries:"
ls -la glauth-* 2>/dev/null || echo "No main binaries found"
echo ""
echo "SHA256 files:"
ls -la *.sha256 2>/dev/null || echo "No SHA256 files found"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.tag.outputs.tag }}
name: Release ${{ steps.tag.outputs.tag }}
draft: false
prerelease: false
generate_release_notes: true
files: v2/bin/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}