summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chaussé <benjamin.chausse@usherbrooke.ca>2023-09-11 14:20:59 -0400
committerBenjamin Chaussé <benjamin.chausse@usherbrooke.ca>2023-09-11 14:20:59 -0400
commitaaa234fbfe60922d641a73829a377aaa2c260c87 (patch)
treed6e2edccfe565de4f75336a52b4f46fb8506dada
parent55fb4d24dc86948598dd2ba545a36bd051b6c2c5 (diff)
parenta7dfa7b787726698117e1837c6f07a723784730a (diff)
Merge branch 'ci-cd' into 'main'
CI/CD doesn't crash See merge request dev/vdi!7
-rw-r--r--.gitlab-ci.yml188
1 files changed, 188 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..cac806a
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,188 @@
+stages:
+ - build
+ - publish
+ - deploy
+
+########## Global variables #########
+variables:
+ DEPLOY_LATEST: ${CI_COMMIT_BRANCH} == "main"
+ PUBLISH_VERSION: ${CI_COMMIT_TAG} != null
+ # Not in georges Template, only add if needed:
+ # CI_JOB_TOKEN: KSL2GVxx3EqgCBWab_YH
+
+########## Service Templates ##########
+# Particularities of each service/container
+.service:
+ before_script:
+ - cd "${SERVICE}"
+ rules:
+ - changes:
+ - "${SERVICE}/**/*"
+
+.service authentication:
+ extends:
+ - .service
+ variables:
+ SERVICE: authentication
+
+.service core:
+ extends:
+ - .service
+ variables:
+ SERVICE: core
+
+.service database:
+ extends:
+ - .service
+ variables:
+ SERVICE: database
+
+.service frontend:
+ extends:
+ - .service
+ variables:
+ SERVICE: frontend
+
+########## Staging Templates ##########
+# (what to do at each stage: build, publish, deploy)
+
+.stage build:
+ stage: build
+
+.stage publish:
+ stage: publish
+ image: docker
+ rules:
+ - if: ${DEPLOY_LATEST} || ${PUBLISH_VERSION}
+ services:
+ - docker:dind
+ variables:
+ IMAGE: "${CI_REGISTRY_IMAGE}/${SERVICE}"
+ script:
+ - docker login --username "${CI_REGISTRY_USER}" --password "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
+ - docker build --tag "${IMAGE}:latest" .
+ - docker push --all-tags "${IMAGE}"
+
+.stage deploy:
+ stage: deploy
+ image: alpine
+ environment: staging
+ rules:
+ - if: ${DEPLOY_LATEST}
+ script:
+ - apk update
+ - apk add openssh-client
+ - eval $(ssh-agent -s)
+ - chmod go= "${SSH_PRIVATE_KEY}"
+ - ssh-add "${SSH_PRIVATE_KEY}"
+ - ssh -o "UserKnownHostsFile=${SSH_HOST_KEY}" "${SSH_DEPLOY_URL}" "${SSH_DEPLOY_COMMAND}" "${SERVICE}"
+
+########## Authentication Pipeline ##########
+# (build->publish->deploy)
+
+build authentication:
+ extends:
+ - .stage build
+ - .service authentication
+ artifacts:
+ paths:
+ - ${SERVICE}/build
+ script:
+ - apk update
+
+publish authentication:
+ extends:
+ - .stage publish
+ - .service authentication
+ needs:
+ - build authentication
+
+deploy authentication:
+ extends:
+ - .stage deploy
+ - .service authentication
+ needs:
+ - publish authentication
+
+########## Core Pipeline ##########
+# (build->publish->deploy)
+# TODO: uncomment once implemented
+
+# build core:
+# extends:
+# - .stage build
+# - .service core
+# artifacts:
+# paths:
+# - ${SERVICE}/build
+# script:
+# - apk update
+
+# publish core:
+# extends:
+# - .stage publish
+# - .service core
+# needs:
+# - build core
+
+# deploy core:
+# extends:
+# - .stage deploy
+# - .service core
+# needs:
+# - publish core
+
+########## Database Pipeline ##########
+# (build->publish->deploy)
+
+build database:
+ extends:
+ - .stage build
+ - .service database
+ artifacts:
+ paths:
+ - ${SERVICE}/build
+ script:
+ - apk update
+
+publish database:
+ extends:
+ - .stage publish
+ - .service database
+ needs:
+ - build database
+
+deploy database:
+ extends:
+ - .stage deploy
+ - .service database
+ needs:
+ - publish database
+
+########## Frontend Pipeline ##########
+# (build->publish->deploy)
+
+build frontend:
+ extends:
+ - .stage build
+ - .service frontend
+ artifacts:
+ paths:
+ - ${SERVICE}/build
+ script:
+ - apk update
+
+publish frontend:
+ extends:
+ - .stage publish
+ - .service frontend
+ needs:
+ - build frontend
+
+deploy frontend:
+ extends:
+ - .stage deploy
+ - .service frontend
+ needs:
+ - publish frontend
+