diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 040c5164fc1dce12366e25d8a23e6d2931f144c7..0c9d899236ec572892134955e6d1b501a1c36cde 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,5 @@ variables: DOCKER_TLS_CERTDIR: "" # HACK: see https://gitlab.com/gitlab-org/gitlab-runner/issues/4501 - DOCKER_IMAGE: "docker:20.10.12" stages: - setup @@ -8,7 +7,9 @@ stages: - build - deploy -#==[ Node jobs templates ]====================================================== +# TODO: maybe stup some notifications as a last stage? + +#==[ JOB TEMPLATES ]============================================================ .node-job: &node-job image: node:16-alpine @@ -42,7 +43,9 @@ stages: - cd backend - npm ci --cache .npm --prefer-offline -#==[ Frontent cache ]=========================================================== +#==[ SETUP STAGE ]============================================================== + +#--[ Frontend ]----------------------------------------------------------------- cache-fe-node-job: extends: .fe-node-job @@ -50,7 +53,7 @@ cache-fe-node-job: script: - echo "Done!" -#==[ Backend cache ]============================================================ +#--[ Backend ]------------------------------------------------------------------ cache-be-node-job: extends: .be-node-job @@ -58,7 +61,9 @@ cache-be-node-job: script: - echo "Done!" -#==[ Frontend checks ]========================================================== +#==[ CHECK STAGE ]============================================================== + +#--[ Frontend ]----------------------------------------------------------------- .check-fe-node-job: &check-fe-node-job extends: .fe-node-job @@ -81,7 +86,7 @@ test-fe-node-job: script: - npm run test -#==[ Backend checks ]=========================================================== +#--[ Backend ]------------------------------------------------------------------ .check-be-node-job: &check-be-node-job extends: .be-node-job @@ -104,12 +109,39 @@ test-be-node-job: script: - npm run test -#==[ Backend build ]============================================================ +#==[ BUILD STAGE ]============================================================== + +#--[ Frontend ]----------------------------------------------------------------- + +.fe-build-job: + image: node:16-alpine + stage: build + tags: + - commul + cache: + - key: + files: + - frontend/package-lock.json + paths: + - frontend/node_modules + script: + - cd frontend + - npm install + - npm run build + artifacts: + paths: + - frontend/dist/ + # TODO: set expiration in docker registry too + expire_in: 1 week + only: + - tags + - development + +#--[ Backend ]------------------------------------------------------------------ # TODO: cache docker layers -# TODO: build ts .be-build-job: - image: $DOCKER_IMAGE + image: docker:20.10.12 stage: build tags: - commul @@ -133,110 +165,86 @@ test-be-node-job: - tags - development -#==[ Backend deployment ]======================================================= +#==[ DEPLOY STAGE ]============================================================= -.be-deploy-job: +#--[ Frontend ]----------------------------------------------------------------- + +.fe-deploy-job: image: alpine:latest stage: deploy needs: - - job: be-build-job - artifacts: false + - job: fe-build-job + artifacts: true tags: - commul - variables: - IMAGE_NAME: $CI_REGISTRY_IMAGE/backend before_script: - - ./ci/install-kubectl-on-alpine.sh + - ./ci/install-butler-on-alpine.sh script: - - kubectl set image deployment/${K8S_DEPLOYMENT} oetzi=${IMAGE_NAME}:${CI_COMMIT_SHA} --namespace=${K8S_NAMESPACE} + - > + butler push + frontend/dist + eurac/$GAME_NAME:html5 + --userversion ${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA} -.be-prd-deploy-job: - extends: .be-deploy-job +.fe-prd-deploy-job: + extends: .fe-deploy-job environment: - name: production/backend + name: production/frontend deployment_tier: production - url: https://kommul.eurac.edu/oetzi + url: https://eurac.itch.io/oetzi variables: - K8S_NAMESPACE: kommul - K8S_DEPLOYMENT: oetzi-webserver-deployment + GAME_NAME: oetzi only: - tags -.be-stg-deploy-job: - extends: .be-deploy-job +.fe-stg-deploy-job: + extends: .fe-deploy-job environment: - name: staging/backend + name: staging/frontend deployment_tier: staging - url: https://kommul-dev.eurac.edu/oetzi + url: https://eurac.itch.io/oetzi-staging variables: - K8S_NAMESPACE: kommul-dev - K8S_DEPLOYMENT: oetzi-webserver-deployment - only: - - development - -#==[ Frontend build ]=========================================================== - -.fe-build-job: - image: node:16-alpine - stage: build - tags: - - commul - cache: - - key: - files: - - frontend/package-lock.json - paths: - - frontend/node_modules - script: - - cd frontend - - npm install - - npm run build - artifacts: - paths: - - frontend/dist/ - # TODO: set expiration in docker registry too - expire_in: 1 week + GAME_NAME: oetzi-staging only: - - tags - development -#==[ Frontend deployment ]====================================================== +#--[ Backend ]------------------------------------------------------------------ -.fe-deploy-job: +.be-deploy-job: image: alpine:latest stage: deploy needs: - - job: fe-build-job - artifacts: true + - job: be-build-job + artifacts: false tags: - commul + variables: + IMAGE_NAME: $CI_REGISTRY_IMAGE/backend before_script: - - ./ci/install-butler-on-alpine.sh + - ./ci/install-kubectl-on-alpine.sh script: - - > - butler push - frontend/dist - eurac/$GAME_NAME:html5 - --userversion ${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA} + - kubectl set image deployment/${K8S_DEPLOYMENT} oetzi=${IMAGE_NAME}:${CI_COMMIT_SHA} --namespace=${K8S_NAMESPACE} -.fe-prd-deploy-job: - extends: .fe-deploy-job +.be-prd-deploy-job: + extends: .be-deploy-job environment: - name: production/frontend + name: production/backend deployment_tier: production - url: https://eurac.itch.io/oetzi + url: https://kommul.eurac.edu/oetzi variables: - GAME_NAME: oetzi + K8S_NAMESPACE: kommul + K8S_DEPLOYMENT: oetzi-webserver-deployment only: - tags -.fe-stg-deploy-job: - extends: .fe-deploy-job +.be-stg-deploy-job: + extends: .be-deploy-job environment: - name: staging/frontend + name: staging/backend deployment_tier: staging - url: https://eurac.itch.io/oetzi-staging + url: https://kommul-dev.eurac.edu/oetzi variables: - GAME_NAME: oetzi-staging + K8S_NAMESPACE: kommul-dev + K8S_DEPLOYMENT: oetzi-webserver-deployment only: - development