ldc-gen-game-web/deployment/.gitlab-ci.yml
2024-01-04 15:11:38 +01:00

163 lines
4.4 KiB
YAML

repo-build:
stage: build
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/ldcweb-qa-8.2:latest
before_script:
- git clone https://gitlab-ci-token:${GGW_TOKEN}@lab.s-web.fr/ldc-web/projets/gen-game-web.git ggw --branch $APP_GGW_TAG --single-branch
- cd ggw
script:
- git clone https://gitlab-ci-token:${GGW_THEME_TOKEN}@lab.s-web.fr/ldc-web/projets/gen-game-web-themes/${APP_THEME_PATH}.git resources/theme/mounted --branch main --single-branch
cache:
paths:
- ggw
artifacts:
expose_as: 'ggw'
paths:
- ggw/
allow_failure: false
rules:
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master"
composer-build:
stage: build
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/ldcweb-qa-8.2:latest
before_script:
- cd ggw
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
cache:
paths:
- ggw
script:
- composer install --no-dev --optimize-autoloader --classmap-authoritative --no-scripts
artifacts:
expose_as: 'vendor'
paths:
- ggw/
allow_failure: false
dependencies:
- repo-build
needs:
- job: repo-build
optional: true
rules:
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master"
npm-build:
stage: build
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/ldcweb-qa-8.2:latest
before_script:
- cd ggw
- npm config set @ldc-web:registry https://${CI_SERVER_HOST}/api/v4/packages/npm/
- npm config set -- '//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken' "${CI_DEPLOY_PASSWORD}"
- npm install
cache:
paths:
- ggw
script:
- npm run prod
artifacts:
expose_as: 'front-build'
paths:
- ggw/
allow_failure: false
dependencies:
- composer-build
needs:
- job: composer-build
optional: true
rules:
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master"
.docker-build:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.9.1-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${IMAGE_TAG}"
allow_failure: false
dependencies:
- npm-build
- composer-build
needs:
- job: npm-build
optional: true
- job: composer-build
optional: true
docker-build:staging:
extends: .docker-build
variables:
IMAGE_TAG: "${CI_REGISTRY_IMAGE}:s-${CI_PIPELINE_IID}"
rules:
- if: $CI_COMMIT_BRANCH == "trunk"
docker-build:production:
extends: .docker-build
variables:
IMAGE_TAG: "${CI_REGISTRY_IMAGE}:p-${CI_PIPELINE_IID}"
rules:
- if: $CI_COMMIT_BRANCH == "master"
.kubernetes:
stage: deploy
image:
name: alpine/k8s:1.26.0
entrypoint: ['']
variables:
KUBE_CONTEXT: ldc-web/cluster-k8s:k8s-ldc-web
KUBE_NAMESPACE: default
before_script:
- kubectl config use-context ${KUBE_CONTEXT}
script:
- envsubst < manifest.yaml | kubectl apply --namespace ${KUBE_NAMESPACE} -f -
.kubernetes_stop:
extends: .kubernetes
script:
- envsubst < manifest.yaml | kubectl delete --namespace ${KUBE_NAMESPACE} -f -
when: manual
environment:
action: stop
kubernetes:staging:
extends: .kubernetes
variables:
KUBE_NAMESPACE: staging
IMAGE_TAG: "${CI_REGISTRY_IMAGE}:s-${CI_PIPELINE_IID}"
rules:
- if: $CI_COMMIT_BRANCH == "trunk"
when: manual
environment:
name: staging
url: https://${DOMAIN}
on_stop: kubernetes_stop:staging
kubernetes_stop:staging:
extends: .kubernetes_stop
variables:
KUBE_NAMESPACE: staging
rules:
- if: $CI_COMMIT_BRANCH == "trunk"
environment:
name: staging
kubernetes:prod:
extends: .kubernetes
variables:
KUBE_NAMESPACE: production
IMAGE_TAG: "${CI_REGISTRY_IMAGE}:p-${CI_PIPELINE_IID}"
rules:
- if: $CI_COMMIT_BRANCH == "master"
when: manual
environment:
name: production
url: https://${APP_DOMAIN}
stages:
- build
- deploy