-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,116 @@ | ||
image: docker:20.10.16 | ||
|
||
stages: | ||
- build | ||
|
||
variables: | ||
REGISTRY: "ghcr.io" | ||
IMAGE_BACKEND: "ticketz-oss/ticketz-backend" | ||
IMAGE_FRONTEND: "ticketz-oss/ticketz-frontend" | ||
DOCKER_CONFIG: /kaniko/.docker/ | ||
DOCKER_DRIVER: overlay2 | ||
DOCKER_BUILDKIT: 1 | ||
DOCKER_CLI_EXPERIMENTAL: enabled | ||
DOCKER_HOST: tcp://docker:2375 | ||
DOCKER_TLS_CERTDIR: "" | ||
services: | ||
- docker:20.10.16-dind | ||
|
||
before_script: | ||
- echo "{\"auths\":{\"$REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json | ||
- export BASE_TAG=$(echo $CI_COMMIT_TAG | sed 's/^v//;s/-.*$//') | ||
- export SUFFIX=$(echo $CI_COMMIT_TAG | sed 's/^v[^-]*-//') | ||
- export TAG_MAJOR=$(echo $BASE_TAG | cut -d'.' -f1) | ||
- export TAG_MINOR=$(echo $BASE_TAG | cut -d'.' -f1,2) | ||
- export TAG_PATCH=$(echo $BASE_TAG | cut -d'.' -f1,2,3) | ||
- export BUILD_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
- docker login $REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD | ||
- docker run --privileged --rm tonistiigi/binfmt --install all | ||
- docker buildx create --name mybuilder --use | ||
- docker buildx inspect --bootstrap | ||
|
||
# Build and push backend Docker image | ||
build-and-push-backend: | ||
build-backend-amd64: | ||
stage: build | ||
only: | ||
- /^.*-(pro|theme)+$/ | ||
script: | ||
- | | ||
cat <<EOT > backend/src/gitinfo.ts | ||
export const GitInfo = { | ||
commitHash: "$CI_COMMIT_SHORT_SHA", | ||
commitTimestamp: "", | ||
branchName: "$CI_COMMIT_REF_NAME", | ||
tagName: "$CI_COMMIT_TAG", | ||
buildTimestamp: "$BUILD_TIMESTAMP" | ||
}; | ||
EOT | ||
- | | ||
docker buildx build --platform linux/amd64 --push \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$TAG_PATCH-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$TAG_MINOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$TAG_MAJOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_BACKEND:pro backend | ||
build-backend-arm64: | ||
stage: build | ||
image: | ||
name: gcr.io/kaniko-project/executor:v1.14.0-debug | ||
entrypoint: [""] | ||
rules: | ||
- if: '$CI_COMMIT_TAG =~ /-pro$/' | ||
only: | ||
- /^.*-[a-z0-9]+$/ | ||
script: | ||
- | | ||
cat <<EOT > backend/src/gitinfo.ts | ||
export const GitInfo = { | ||
commitHash: "${CI_COMMIT_SHORT_SHA}", | ||
commitTimestamp: "N/A", | ||
branchName: "${CI_COMMIT_REF_NAME", | ||
tagName: "${CI_COMMIT_TAG}", | ||
buildTimestamp: "${BUILD_TIMESTAMP}" | ||
commitHash: "$CI_COMMIT_SHORT_SHA", | ||
commitTimestamp: "", | ||
branchName: "$CI_COMMIT_REF_NAME", | ||
tagName: "$CI_COMMIT_TAG", | ||
buildTimestamp: "$BUILD_TIMESTAMP" | ||
}; | ||
EOT | ||
- | | ||
/kaniko/executor --context "${CI_PROJECT_DIR}/backend" \ | ||
--dockerfile "${CI_PROJECT_DIR}/backend/Dockerfile" \ | ||
--destination "${REGISTRY}/${IMAGE_BACKEND}:${CI_COMMIT_TAG}" \ | ||
--destination "${REGISTRY}/${IMAGE_BACKEND}:latest" \ | ||
--build-arg PLATFORM=linux/amd64,linux/arm64 | ||
docker buildx build --platform linux/arm64 --push \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$TAG_PATCH-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$TAG_MINOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$TAG_MAJOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_BACKEND:$SUFFIX backend | ||
build-frontend-amd64: | ||
stage: build | ||
only: | ||
- /^.*-[a-z0-9]+$/ | ||
script: | ||
- | | ||
cat <<EOT > frontend/public/gitinfo.json | ||
{ | ||
"commitHash": "$CI_COMMIT_SHORT_SHA", | ||
"commitTimestamp": "", | ||
"branchName": "$CI_COMMIT_REF_NAME", | ||
"tagName": "$CI_COMMIT_TAG", | ||
"buildTimestamp": "$BUILD_TIMESTAMP" | ||
} | ||
EOT | ||
- | | ||
docker buildx build --platform linux/amd64 --push \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$TAG_PATCH-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$TAG_MINOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$TAG_MAJOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$SUFFIX frontend | ||
# Build and push frontend Docker image | ||
build-and-push-frontend: | ||
build-frontend-arm64: | ||
only: | ||
- /^.*-[a-z0-9]+$/ | ||
stage: build | ||
image: | ||
name: gcr.io/kaniko-project/executor:v1.14.0-debug | ||
entrypoint: [""] | ||
rules: | ||
- if: '$CI_COMMIT_TAG =~ /-pro$/' | ||
script: | ||
- | | ||
cat <<EOT > frontend/public/gitinfo.json | ||
{ | ||
"commitHash": "${CI_COMMIT_SHORT_SHA}", | ||
"commitTimestamp": "N/A", | ||
"branchName": "${CI_COMMIT_REF_NAME", | ||
"tagName": "${CI_COMMIT_TAG}", | ||
"buildTimestamp": "${BUILD_TIMESTAMP}" | ||
"commitHash": "$CI_COMMIT_SHORT_SHA", | ||
"commitTimestamp": "", | ||
"branchName": "$CI_COMMIT_REF_NAME", | ||
"tagName": "$CI_COMMIT_TAG", | ||
"buildTimestamp": "$BUILD_TIMESTAMP" | ||
} | ||
EOT | ||
- | | ||
/kaniko/executor --context "${CI_PROJECT_DIR}/frontend" \ | ||
--dockerfile "${CI_PROJECT_DIR}/frontend/Dockerfile" \ | ||
--destination "${REGISTRY}/${IMAGE_FRONTEND}:${CI_COMMIT_TAG}" \ | ||
--destination "${REGISTRY}/${IMAGE_FRONTEND}:latest" \ | ||
--build-arg PLATFORM=linux/amd64,linux/arm64 | ||
docker buildx build --platform linux/arm64 --push \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$TAG_PATCH-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$TAG_MINOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$TAG_MAJOR-$SUFFIX \ | ||
-t $REGISTRY/$IMAGE_FRONTEND:$SUFFIX frontend |