Last active
May 13, 2020 17:15
-
-
Save HarmlessEvil/9a1d14a4283dc769b8275624b6eb877c to your computer and use it in GitHub Desktop.
Refined build system for BigSister
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build backend | |
FROM adoptopenjdk/openjdk11:alpine-slim AS build-backend | |
RUN mkdir build | |
WORKDIR build | |
COPY . . | |
RUN ./gradlew installDist | |
RUN mv build/install/bigsister /out | |
# Build frontend | |
FROM node:lts-alpine AS build-frontend | |
RUN mkdir build | |
WORKDIR build | |
COPY site . | |
RUN npm install | |
RUN npm run release | |
RUN mv release /out | |
# You also required to attach secrets.json and config.json somehow to root folder | |
FROM adoptopenjdk/openjdk11:alpine-jre AS build-app | |
COPY --from=build-backend /out /bigsister | |
COPY --from=build-frontend /out /site/release | |
# She does not understand kindness... | |
STOPSIGNAL 9 | |
# She does not feel pain... | |
# HEALTHCHECK CMD "sh" "-c" "curl http://localhost:$PORT/health || exit 1" | |
# She does not fear you... | |
EXPOSE 8080 | |
# She... is your big sister! | |
#AND | |
SHELL [ "/bigsister/bin/bigsister" ] | |
#WATCH | |
#YOU | |
#WORK | |
# You can't hide... | |
ENTRYPOINT "" | |
FROM adoptopenjdk/openjdk11:alpine-jre AS build-local | |
COPY build/install/bigsister /bigsister | |
COPY site/release /site/release | |
# She does not understand kindness... | |
STOPSIGNAL 9 | |
# She does not feel pain... | |
# HEALTHCHECK CMD "sh" "-c" "curl http://localhost:$PORT/health || exit 1" | |
# She does not fear you... | |
EXPOSE 8080 | |
# She... is your big sister! | |
#AND | |
SHELL [ "/bigsister/bin/bigsister" ] | |
#WATCH | |
#YOU | |
#WORK | |
# You can't hide... | |
ENTRYPOINT "" | |
FROM adoptopenjdk/openjdk11:alpine-slim AS build-test | |
COPY . . | |
RUN ./gradlew installDist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
REGISTRY_URL=registry.gitlab.com/grossister/big-sister | |
IMAGE_NAME=bigsister | |
export DOCKER_BUILDKIT=1 | |
help() { | |
cat <<MOW | |
Hi! | |
This script builds images for Big Sister. | |
# $0 build (tag-name) | |
Builds an image from scratch. | |
# $0 local (tag-name) | |
Builds an image using local cache. | |
# $0 push (tag-name) | |
Same as local, but pushes it into "$REGISTRY_URL:tag-name". | |
# $0 test (tag-name) | |
Builds an image for testing, using current filesystem state. | |
MOW | |
exit 1 | |
} | |
main() { | |
case $1 in | |
ci-deploy) | |
deriveBranchTags "$CI_COMMIT_REF_NAME" | |
buildImage build-app | |
push | |
# shellcheck disable=SC2029 | |
ssh [email protected] ./refre.sh "${IMAGE_TAGS[@]}" | |
;; | |
build) | |
deriveBranchTags "$(getGitBranch)" | |
buildImage build-app | |
;; | |
local) | |
deriveBranchTags "$(getGitBranch)" | |
buildImage build-local | |
;; | |
test) | |
deriveBranchTags "$(getGitBranch)" | |
testImage | |
;; | |
push) | |
deriveBranchTags "$(getGitBranch)" | |
buildImage build-local | |
push | |
;; | |
*) help ;; | |
esac | |
} | |
getGitBranch() { | |
git rev-parse --abbrev-ref HEAD | |
} | |
deriveBranchTags() { | |
local BRANCH=$1 | |
IMAGE_TAGS=("${BRANCH/'/'/_}") | |
case $BRANCH in | |
release) | |
# also derive version tag | |
source version.properties | |
IMAGE_TAGS+=("$versionName") | |
;; | |
esac | |
} | |
testImage() { | |
echo "Engaging tests..." | |
NETNAME=${RANDOM}-bs-testnet | |
docker build --target build-test ./ -t "bigsister-test" | |
docker network create $NETNAME | |
C_MONGO=$(docker run -d --rm --network $NETNAME --network-alias mongo mongo:latest) | |
docker run \ | |
--rm --network=$NETNAME \ | |
-e "DB_HOST=mongo" \ | |
-v "$TEST_LOGS/test-results:/build/build/test-results" \ | |
-v "$TEST_LOGS/reports:/build/build/reports" \ | |
"bigsister-test:latest" ./gradlew testCoverage \ | |
|| TEST_FAILURE=1 | |
docker image rm bigsister-test | |
docker kill $C_MONGO | |
docker network rm $NETNAME | |
[[ -n $TEST_FAILURE ]] && exit 1 | |
} | |
buildImage() { | |
docker build --target "$1" --network=host ./ -t "${IMAGE_NAME}:latest" | |
tag | |
} | |
tag() { | |
for TAG in "${IMAGE_TAGS[@]}"; do | |
echo "Tagging image as $IMAGE_NAME:$TAG" | |
docker tag $IMAGE_NAME:latest "$IMAGE_NAME:$TAG" | |
done | |
} | |
push() { | |
for TAG in "${IMAGE_TAGS[@]}"; do | |
REGISTRY_NAME="$REGISTRY_URL/$IMAGE_NAME:$TAG" | |
echo "Pushing $REGISTRY_URL" | |
docker tag $IMAGE_NAME:latest "$REGISTRY_NAME" | |
docker push "$REGISTRY_NAME" | |
done | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment