Skip to content

Commit 44c46d9

Browse files
committed
Fix CI
1 parent 48df0ee commit 44c46d9

File tree

7 files changed

+172
-88
lines changed

7 files changed

+172
-88
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
._*
55
*.code-workspace
66
vendor
7-
dist
7+
bin/*
88
backend/config.json
99
backend/internal/api/handler/assets
1010
test/node_modules

Jenkinsfile

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,11 @@ pipeline {
4646
}
4747
}
4848
}
49-
stage('Versions') {
50-
steps {
51-
// Is this frontend version stuff still applicable?
52-
sh 'cat frontend/package.json | jq --arg BUILD_VERSION "${BUILD_VERSION}" \'.version = $BUILD_VERSION\' | sponge frontend/package.json'
53-
sh 'echo -e "\\E[1;36mFrontend Version is:\\E[1;33m $(cat frontend/package.json | jq -r .version)\\E[0m"'
54-
sh 'sed -i -E "s/(version-)[0-9]+\\.[0-9]+\\.[0-9]+(-green)/\\1${BUILD_VERSION}\\2/" README.md'
55-
}
56-
}
5749
}
5850
}
5951
stage('Frontend') {
6052
steps {
61-
sh './scripts/ci/frontend-build'
53+
sh './scripts/ci/build-frontend'
6254
}
6355
post {
6456
always {
@@ -69,18 +61,17 @@ pipeline {
6961
}
7062
stage('Backend') {
7163
steps {
72-
withCredentials([usernamePassword(credentialsId: 'oss-index-token', passwordVariable: 'NANCY_TOKEN', usernameVariable: 'NANCY_USER')]) {
73-
sh '''docker build --pull --no-cache --squash --compress \\
64+
withCredentials([string(credentialsId: 'npm-sentry-dsn', variable: 'SENTRY_DSN')]) {
65+
withCredentials([usernamePassword(credentialsId: 'oss-index-token', passwordVariable: 'NANCY_TOKEN', usernameVariable: 'NANCY_USER')]) {
66+
sh './scripts/ci/test-backend'
67+
}
68+
sh './scripts/ci/build-backend'
69+
sh '''docker build --pull --no-cache \\
7470
-t "${IMAGE}:${BRANCH_LOWER}-ci-${BUILD_NUMBER}" \\
7571
-f docker/Dockerfile \\
76-
--build-arg BUILD_COMMIT="${BUILD_COMMIT:-dev}" \\
72+
--build-arg BUILD_COMMIT="${BUILD_COMMIT}" \\
7773
--build-arg BUILD_DATE="$(date '+%Y-%m-%d %T %Z')" \\
7874
--build-arg BUILD_VERSION="${BUILD_VERSION}" \\
79-
--build-arg GOPRIVATE="${GOPRIVATE:-}" \\
80-
--build-arg GOPROXY="${GOPROXY:-}" \\
81-
--build-arg NANCY_TOKEN="${NANCY_TOKEN:-}" \\
82-
--build-arg NANCY_USER="${NANCY_USER:-}" \\
83-
--build-arg SENTRY_DSN="${SENTRY_DSN:-}" \\
8475
.
8576
'''
8677
}

docker/Dockerfile

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,51 @@
11
# This is a Dockerfile intended to be built using `docker buildx`
22
# for multi-arch support. Building with `docker build` may have unexpected results.
33

4-
# This file assumes that the frontend has been built using ./scripts/frontend-build
4+
# This file assumes that these scripts have been run first:
5+
# - ./scripts/ci/build-frontend
56

6-
#===============
7-
# gobuild
8-
#===============
9-
10-
FROM jc21/nginx-full:github-acme.sh-golang AS gobuild
7+
FROM jc21/gotools:latest AS gobuild
118

129
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1310

1411
ARG BUILD_COMMIT
1512
ARG BUILD_VERSION
1613
ARG GOPRIVATE
1714
ARG GOPROXY
18-
ARG NANCY_TOKEN
19-
ARG NANCY_USER
2015
ARG SENTRY_DSN
21-
ARG SKIP_TESTS
2216

2317
ENV BUILD_COMMIT="${BUILD_COMMIT:-dev}" \
2418
BUILD_VERSION="${BUILD_VERSION:-0.0.0}" \
2519
CGO_ENABLED=1 \
2620
GO111MODULE=on \
2721
GOPRIVATE="${GOPRIVATE:-}" \
2822
GOPROXY="${GOPROXY:-}" \
29-
NANCY_TOKEN="${NANCY_TOKEN:-}" \
30-
NANCY_USER="${NANCY_USER:-}" \
31-
SENTRY_DSN="${SENTRY_DSN:-}" \
32-
SKIP_TESTS="${SKIP_TESTS:-}"
23+
SENTRY_DSN="${SENTRY_DSN:-}"
3324

34-
# Code
35-
RUN mkdir -p /app
25+
COPY backend /app
3626
WORKDIR /app
37-
COPY . .
38-
RUN ./scripts/docker-gobuild
27+
28+
RUN mkdir -p /dist \
29+
&& go build \
30+
-ldflags "-w -s -X main.commit=${BUILD_COMMIT:-notset} -X main.version=${BUILD_VERSION} -X main.sentryDSN=${SENTRY_DSN:-}" \
31+
-o "/dist/server" \
32+
./cmd/server
3933

4034
#===============
4135
# Final image
4236
#===============
4337

4438
FROM jc21/nginx-full:github-acme.sh AS final
4539

46-
COPY --from=gobuild /app/dist /app
47-
COPY --from=gobuild /app/backend/migrations /app/migrations
40+
COPY --from=gobuild /dist/server /app/server
41+
COPY backend/migrations /app/migrations
4842

4943
ENV SUPPRESS_NO_CONFIG_WARNING=1
5044
ENV S6_FIX_ATTRS_HIDDEN=1
5145
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf
5246

5347
# s6 overlay
54-
RUN curl -L -o /tmp/s6-overlay-amd64.tar.gz "https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-amd64.tar.gz" \
48+
RUN curl -L -o /tmp/s6-overlay-amd64.tar.gz "https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.3/s6-overlay-amd64.tar.gz" \
5549
&& tar -xzf /tmp/s6-overlay-amd64.tar.gz -C /
5650

5751
EXPOSE 80/tcp 81/tcp 443/tcp

scripts/ci/build-backend

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
set -e
3+
4+
IMAGE=jc21/gotools:latest
5+
6+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
. "$DIR/../.common.sh"
8+
9+
BUILD_DATE=$(date '+%Y-%m-%d %T %Z')
10+
NOW=$(date --rfc-3339=s)
11+
12+
cd $DIR/../..
13+
14+
if [ "$BUILD_COMMIT" = "" ]; then
15+
BUILD_COMMIT=$(git log -n 1 --format=%h)
16+
fi
17+
18+
if [ "$BUILD_VERSION" = "" ]; then
19+
BUILD_VERSION=$(cat .version)
20+
fi
21+
22+
echo -e "${BLUE}${GREEN}build-backend:${RESET}"
23+
echo " BUILD_COMMIT: ${BUILD_COMMIT:-notset}"
24+
echo " BUILD_DATE: $BUILD_DATE"
25+
echo " BUILD_VERSION: $BUILD_VERSION"
26+
echo " CGO_ENABLED: ${CGO_ENABLED:-not set}"
27+
echo " GO111MODULE: ${GO111MODULE:-}"
28+
echo " GOPRIVATE: ${GOPRIVATE:-}"
29+
echo " GOPROXY: ${GOPROXY:-}"
30+
echo " NOW: $NOW"
31+
32+
cleanup() {
33+
docker run --rm -v "$(pwd):/app" "${IMAGE}" chown -R "$(id -u):$(id -g)" /app/bin
34+
}
35+
36+
build_backend() {
37+
echo -e "${BLUE}${CYAN}Building backend for ${YELLOW}${1}-${2} ...${RESET}"
38+
39+
FILENAME="nginxproxymanager-v${BUILD_VERSION}_${1}_${2}"
40+
if [ "$1" = "windows" ]; then
41+
FILENAME="${FILENAME}.exe"
42+
fi
43+
44+
docker run --rm \
45+
-e BUILD_COMMIT="${BUILD_COMMIT:-notset}" \
46+
-e BUILD_DATE="$BUILD_DATE" \
47+
-e BUILD_VERSION="$BUILD_VERSION" \
48+
-e GOARCH="${2}" \
49+
-e GOOS="${1}" \
50+
-e GOPRIVATE="${GOPRIVATE:-}" \
51+
-e GOPROXY="${GOPROXY:-}" \
52+
-e NOW="$NOW" \
53+
-e SENTRY_DSN="${SENTRY_DSN:-}" \
54+
-e TZ="${TZ:-Australia/Brisbane}" \
55+
-v "$(pwd):/app" \
56+
-w '/app/backend' \
57+
"${IMAGE}" \
58+
go build \
59+
-ldflags "-w -s -X main.commit=${BUILD_COMMIT:-notset} -X main.version=${BUILD_VERSION} -X main.sentryDSN=${SENTRY_DSN:-}" \
60+
-o "/app/bin/$FILENAME" \
61+
./cmd/server
62+
}
63+
64+
docker pull "${IMAGE}"
65+
66+
build_backend "darwin" "amd64"
67+
build_backend "darwin" "arm64"
68+
build_backend "linux" "amd64"
69+
build_backend "linux" "arm64"
70+
build_backend "linux" "arm"
71+
build_backend "openbsd" "amd64"
72+
build_backend "windows" "amd64"
73+
74+
cleanup
75+
76+
echo -e "${BLUE}${GREEN}build-backend completed${RESET}"
77+
exit 0
78+
79+
trap cleanup EXIT
File renamed without changes.

scripts/ci/test-backend

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
set -e
3+
4+
IMAGE=jc21/gotools:latest
5+
6+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
. "$DIR/../.common.sh"
8+
9+
BUILD_DATE=$(date '+%Y-%m-%d %T %Z')
10+
NOW=$(date --rfc-3339=s)
11+
cd $DIR/../..
12+
13+
if [ "$BUILD_COMMIT" = "" ]; then
14+
BUILD_COMMIT=$(git log -n 1 --format=%h)
15+
fi
16+
17+
if [ "$BUILD_VERSION" = "" ]; then
18+
BUILD_VERSION=$(cat .version)
19+
fi
20+
21+
echo -e "${BLUE}${GREEN}test-backend: ${YELLOW}${1:-}${RESET}"
22+
echo " BUILD_COMMIT: ${BUILD_COMMIT:-notset}"
23+
echo " BUILD_DATE: $BUILD_DATE"
24+
echo " BUILD_VERSION: $BUILD_VERSION"
25+
echo " CGO_ENABLED: ${CGO_ENABLED:-not set}"
26+
echo " GO111MODULE: ${GO111MODULE:-}"
27+
echo " GOPRIVATE: ${GOPRIVATE:-}"
28+
echo " GOPROXY: ${GOPROXY:-}"
29+
echo " NOW: $NOW"
30+
31+
if [ "${1:-}" = "--inside-docker" ]; then
32+
mkdir -p /workspace
33+
echo -e "${BLUE}${CYAN}Nancy setup${RESET}"
34+
cd /workspace
35+
# go get github.com/sonatype-nexus-community/nancy
36+
cp /app/backend/go.mod /app/backend/go.sum /app/backend/.nancy-ignore .
37+
go mod download
38+
39+
echo -e "${BLUE}${CYAN}Nancy testing${RESET}"
40+
go list -json -m all | nancy sleuth --quiet --username "${NANCY_USER}" --token "${NANCY_TOKEN:-}"
41+
rm -rf /workspace
42+
43+
echo -e "${BLUE}${CYAN}Testing backend code${RESET}"
44+
cd /app/backend
45+
[ -z "$(go tool fix -diff ./internal)" ]
46+
richgo test -cover -v ./internal/...
47+
richgo test -bench=. ./internal/...
48+
golangci-lint -v run ./...
49+
else
50+
# run this script from within docker
51+
docker pull "${IMAGE}"
52+
docker run --rm \
53+
-e BUILD_COMMIT="${BUILD_COMMIT:-notset}" \
54+
-e BUILD_DATE="$BUILD_DATE" \
55+
-e BUILD_VERSION="$BUILD_VERSION" \
56+
-e GOARCH="${2}" \
57+
-e GOOS="${1}" \
58+
-e GOPRIVATE="${GOPRIVATE:-}" \
59+
-e GOPROXY="${GOPROXY:-}" \
60+
-e NOW="$NOW" \
61+
-e SENTRY_DSN="${SENTRY_DSN:-}" \
62+
-e TZ="${TZ:-Australia/Brisbane}" \
63+
-v "$(pwd):/app" \
64+
-w '/app/backend' \
65+
"${IMAGE}" \
66+
/app/scripts/ci/test-backend --inside-docker
67+
fi
68+
69+
echo -e "${BLUE}${GREEN}test-backend ${YELLOW}${1:-} ${GREEN}completed${RESET}"
70+
exit 0

scripts/docker-gobuild

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)