Files
reloading-manager/.gitlab-ci.yml
2025-04-21 18:39:16 -04:00

135 lines
3.8 KiB
YAML

stages:
- Tests
- Build
- Update Deployment
- Create Commit
- Create Merge Request
- Trigger
NodeJs Tests:
stage: Tests
image: node:22.14.0
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
changes:
- frontend/**
- frontend/.gitlab-ci.yml
before_script:
- cd frontend
- npm install
script:
- npm run build
include:
- project: 'shared/blueprints'
file: 'jobs/golang-tests.yml'
ref: master
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
changes:
- backend/**
- backend/.gitlab-ci.yml
inputs:
job_name: "Go Tests"
working_directory: "backend"
stage: Tests
- project: 'shared/blueprints'
file: 'jobs/docker-build.yml'
ref: master
rules:
- if: '$CI_COMMIT_TAG'
inputs:
jobName: "build backend"
dockerHubUser: ${DOCKER_HUB_USER}
dockerHubPat: ${DOCKER_HUB_PAT}
registry: "scr.siteworxpro.com"
registryUser: ${REGISTRY_USER}
registryPassword: ${REGISTRY_PASSWORD}
stage: Build
repo: "scr.siteworxpro.com/reloading-manager/backend"
tag: "${CI_COMMIT_TAG}"
context: "backend"
dockerfile: "backend/Dockerfile"
- project: 'shared/blueprints'
file: 'jobs/docker-build.yml'
ref: master
rules:
- if: '$CI_COMMIT_TAG'
inputs:
jobName: "build frontend"
dockerHubUser: ${DOCKER_HUB_USER}
dockerHubPat: ${DOCKER_HUB_PAT}
registry: "scr.siteworxpro.com"
registryUser: ${REGISTRY_USER}
registryPassword: ${REGISTRY_PASSWORD}
stage: Build
repo: "scr.siteworxpro.com/reloading-manager/frontend"
tag: "${CI_COMMIT_TAG}"
context: "frontend"
dockerfile: "frontend/Dockerfile"
- project: 'shared/blueprints'
file: 'jobs/trigger-argocd.yml'
ref: master
rules:
- changes:
- argocd/**/*
inputs:
stage: Trigger
argocdServer: ${ARGOCD_SERVER}
argocdAuthToken: ${ARGOCD_AUTH_TOKEN}
argocdAppName: ${ARGOCD_APP_NAME}
Update Deployment:
image: siteworxpro/alpine:3.21.3
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
stage: Update Deployment
script: |
echo "## Do not edit this file directly. It is auto-generated by the script." > argocd/deployment/deployment.yml
sed "s|__TAG__|${CI_COMMIT_TAG}|g" argocd/template/deployment.yml >> argocd/deployment/deployment.yml
artifacts:
expire_in: 1 hour
paths:
- argocd/deployment/deployment.yml
Create Commit:
stage: Create Commit
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
dependencies:
- Update Deployment
image: siteworxpro/git:2.49.0
before_script: |
git config --global user.name "${GITLAB_USER_NAME} via Gitlab Runner"
git config --global user.email "${GITLAB_USER_EMAIL}"
script: |
git pull origin master
git checkout -b "update-deployment-${CI_COMMIT_TAG}"
git add argocd/deployment/deployment.yml
git commit -m "Update deployment manifest with new image tags"
git push --push-option='ci.skip' origin "update-deployment-${CI_COMMIT_TAG}"
Create Merge Request:
stage: Create Merge Request
dependencies:
- Create Commit
image: siteworxpro/alpine:3.21.3
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
before_script: |
apk add --no-cache curl
script: |
curl --request POST --header "PRIVATE-TOKEN: glpat-hv-uxCx3PDNKn7ihyXce" \
--data "source_branch=update-deployment-${CI_COMMIT_TAG}" \
--data "target_branch=master" \
--data "title=Update deployment manifest for version ${CI_COMMIT_TAG}" \
--data "description=This merge request updates the deployment manifest with the new image tags." \
--data "remove_source_branch=true" \
--data "squash_commits=true" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests"