Skip to content

Commit 5ed25b4

Browse files
committed
feat: enhance Docker workflow for plugin builds with consistent dependency management
- Added steps to create a vendor directory and ensure consistent builds across SQLite, MySQL, and PostgreSQL plugins. - Implemented backup and restoration of go.mod and go.sum files to maintain original module configurations during builds. - Updated module names and added plugin-specific dependencies for improved reliability and clarity in the build process.
1 parent bdbeb26 commit 5ed25b4

1 file changed

Lines changed: 60 additions & 6 deletions

File tree

.github/workflows/docker-deploy.yml

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,98 @@ jobs:
8888
go mod verify
8989
go mod tidy
9090
91+
# Create vendor directory to ensure consistent builds
92+
go mod vendor
93+
9194
GO_RELEASE_V=$(go version | { read _ _ v _; echo ${v#go}; })
9295
9396
# Build SQLite plugin
9497
if [ -d "pkg/plugins/glauth-sqlite" ]; then
9598
echo "Building SQLite plugin..."
9699
cd pkg/plugins/glauth-sqlite
97-
go mod download
98-
go mod verify
100+
101+
# Use the main module's go.mod and go.sum for consistent builds
102+
cp ../../../go.mod ./go.mod.backup 2>/dev/null || true
103+
cp ../../../go.sum ./go.sum.backup 2>/dev/null || true
104+
105+
# Update module name but keep all dependencies from main module
106+
sed 's/^module.*/module github.com\/glauth\/glauth-sqlite/' ../../../go.mod > go.mod
107+
cp ../../../go.sum go.sum
108+
109+
# Add plugin-specific dependencies
110+
go mod edit -require=github.com/mattn/go-sqlite3@v1.14.15
99111
go mod tidy
112+
100113
xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out sqlite -dest ../../../bin \
101114
-buildmode=plugin -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64" \
102115
-env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct" .
116+
117+
# Restore original go.mod if it existed
118+
if [ -f "./go.mod.backup" ]; then
119+
mv ./go.mod.backup ./go.mod
120+
mv ./go.sum.backup ./go.sum
121+
fi
122+
103123
cd ../../..
104124
fi
105125
106126
# Build MySQL plugin
107127
if [ -d "pkg/plugins/glauth-mysql" ]; then
108128
echo "Building MySQL plugin..."
109129
cd pkg/plugins/glauth-mysql
110-
go mod download
111-
go mod verify
130+
131+
# Use the main module's go.mod and go.sum for consistent builds
132+
cp ../../../go.mod ./go.mod.backup 2>/dev/null || true
133+
cp ../../../go.sum ./go.sum.backup 2>/dev/null || true
134+
135+
# Update module name but keep all dependencies from main module
136+
sed 's/^module.*/module github.com\/glauth\/glauth-mysql/' ../../../go.mod > go.mod
137+
cp ../../../go.sum go.sum
138+
139+
# Add plugin-specific dependencies
140+
go mod edit -require=github.com/go-sql-driver/mysql@v1.6.0
112141
go mod tidy
142+
113143
xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out mysql -dest ../../../bin \
114144
-buildmode=plugin -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64" \
115145
-env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct" .
146+
147+
# Restore original go.mod if it existed
148+
if [ -f "./go.mod.backup" ]; then
149+
mv ./go.mod.backup ./go.mod
150+
mv ./go.sum.backup ./go.sum
151+
fi
152+
116153
cd ../../..
117154
fi
118155
119156
# Build PostgreSQL plugin
120157
if [ -d "pkg/plugins/glauth-postgres" ]; then
121158
echo "Building PostgreSQL plugin..."
122159
cd pkg/plugins/glauth-postgres
123-
go mod download
124-
go mod verify
160+
161+
# Use the main module's go.mod and go.sum for consistent builds
162+
cp ../../../go.mod ./go.mod.backup 2>/dev/null || true
163+
cp ../../../go.sum ./go.sum.backup 2>/dev/null || true
164+
165+
# Update module name but keep all dependencies from main module
166+
sed 's/^module.*/module github.com\/glauth\/glauth-postgres/' ../../../go.mod > go.mod
167+
cp ../../../go.sum go.sum
168+
169+
# Add plugin-specific dependencies
170+
go mod edit -require=github.com/lib/pq@v1.10.7
125171
go mod tidy
172+
126173
xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out postgres -dest ../../../bin \
127174
-buildmode=plugin -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64" \
128175
-env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct" .
176+
177+
# Restore original go.mod if it existed
178+
if [ -f "./go.mod.backup" ]; then
179+
mv ./go.mod.backup ./go.mod
180+
mv ./go.sum.backup ./go.sum
181+
fi
182+
129183
cd ../../..
130184
fi
131185

0 commit comments

Comments
 (0)