Skip to content
Snippets Groups Projects
Verified Commit 1391f4c3 authored by Mustafa Soylu's avatar Mustafa Soylu
Browse files

update gitlab ci

parent 3ce83e0c
No related branches found
No related tags found
1 merge request!15k8s deployment
Pipeline #513223 failed
stages:
- build
- deploy
- sync
docs-build:
# Job for building and pushing Docker image for the development environment
build_dev:
image: docker:stable
stage: build
image: node:20
tags:
- docker
services:
- name: docker:27.3.1-dind
alias: docker
variables:
DOCKER_IMAGE_BASE: "$CI_REGISTRY_IMAGE" # Base image name without a tag
DOCKER_IMAGE_TAG: "develop" # Tag for this branch
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
- npm install
- npm run build
# Full image name with tag
- IMAGE_NAME="$DOCKER_IMAGE_BASE:$DOCKER_IMAGE_TAG"
- IMAGE_NAME_SHA="$DOCKER_IMAGE_BASE:$DOCKER_IMAGE_TAG-$CI_COMMIT_SHA"
# Build the image with the SHA-specific tag
- docker build -build-arg SERVER_URL="$SERVER_URL" --build-arg NODE_ENV=dev -t "$IMAGE_NAME_SHA" .
# Tag the image as 'develop:latest'
- docker tag "$IMAGE_NAME_SHA" "$IMAGE_NAME"
# Push both tags
- docker push "$IMAGE_NAME_SHA"
- docker push "$IMAGE_NAME"
# Save IMAGE_NAME_SHA to a file
- echo "$IMAGE_NAME_SHA" > image_name_sha.txt
artifacts:
paths:
- build
- image_name_sha.txt
expire_in: 1 hour # Optional: Set how long the artifact is kept
rules:
- if: '$CI_COMMIT_BRANCH == "develop" or $CI_COMMIT_BRANCH == "18-k8s-deployment"' # temporary or
exists:
- Dockerfile
# Update backend-manifests repository with the new image tag
update_manifests_dev:
image: bitnami/git:latest
stage: sync
variables:
MANIFESTS_REPO: "https://codebase.helmholtz.cloud/hmc/hmc-public/unhide/development/devops/documentation-manifests.git"
dependencies:
- build_dev # Ensure the artifact is downloaded from the build_dev job
before_script:
- git config --global user.name "GitLab CI"
- git config --global user.email "ci@backend.manifests"
- git config --global credential.helper 'store --file=/tmp/git-credentials'
- echo "https://$DEPLOY_TOKEN_USERNAME:$DEPLOY_TOKEN_PASSWORD@codebase.helmholtz.cloud" > /tmp/git-credentials
# Retrieve the IMAGE_NAME_SHA from the artifact
- IMAGE_NAME_SHA=$(cat image_name_sha.txt)
- echo "Using IMAGE_NAME_SHA=$IMAGE_NAME_SHA"
pages:
stage: deploy
image: busybox:latest
needs: [docs-build]
script:
- mv build public
# Clone the repository
- git clone "$MANIFESTS_REPO" backend-manifests
- cd documentation-manifests/dev
# Update the image tag in the deployment manifest
- 'sed -i "s|image: .*|image: $IMAGE_NAME_SHA|g" deployment.yaml'
# Commit and push changes
- git add deployment.yaml
- git commit -m "Update image to $IMAGE_NAME_SHA"
- git push
artifacts:
paths:
- public
expire_in: 1 hour # Optional: Set artifact expiration for the sync job
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: '$CI_COMMIT_BRANCH == "develop"'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment