|
| 1 | +image: node:20 |
| 2 | + |
| 3 | +stages: |
| 4 | + - build |
| 5 | + - docker |
| 6 | + - release |
| 7 | + |
| 8 | +# AutoDevOps templates for security |
| 9 | +include: |
| 10 | + - template: Jobs/Secret-Detection.gitlab-ci.yml |
| 11 | + - template: Jobs/Dependency-Scanning.gitlab-ci.yml |
| 12 | + |
| 13 | +.frontend-cache: &frontend-cache |
| 14 | + # See https://pnpm.io/continuous-integration#gitlab-ci |
| 15 | + cache: |
| 16 | + key: |
| 17 | + files: |
| 18 | + - pnpm-lock.yaml |
| 19 | + paths: |
| 20 | + - .pnpm-store |
| 21 | + |
| 22 | +.staging-env: &staging-env |
| 23 | + environment: |
| 24 | + name: staging |
| 25 | + url: "https://my-website.test" |
| 26 | + variables: |
| 27 | + NUXT_PUBLIC_API_URL: "https://my-website.test" |
| 28 | + NUXT_PUBLIC_SITE_URL: "https://my-website.test" |
| 29 | + NUXT_PUBLIC_INTERVENTION_REQUEST_BASE_URL: "https://my-website.test/assets" |
| 30 | + NUXT_PUBLIC_INTERVENTION_REQUEST_NO_PROCESS_BASE_URL: "https://my-website.test/files" |
| 31 | + NUXT_APP_CHANNEL: "$CI_COMMIT_SHORT_SHA $CI_ENVIRONMENT_NAME" |
| 32 | + |
| 33 | +.production-env: &production-env |
| 34 | + environment: |
| 35 | + name: production |
| 36 | + url: "https://www.my-website.test" |
| 37 | + variables: |
| 38 | + NUXT_PUBLIC_API_URL: "https://www.my-website.test" |
| 39 | + NUXT_PUBLIC_SITE_URL: "https://www.my-website.test" |
| 40 | + NUXT_PUBLIC_INTERVENTION_REQUEST_BASE_URL: "https://www.my-website.test/assets" |
| 41 | + NUXT_PUBLIC_INTERVENTION_REQUEST_NO_PROCESS_BASE_URL: "https://www.my-website.test/files" |
| 42 | + NUXT_APP_CHANNEL: "$CI_COMMIT_SHORT_SHA $CI_ENVIRONMENT_NAME" |
| 43 | + |
| 44 | + |
| 45 | +## Common scripts and artifacts for develop and main jobs |
| 46 | +.build-commons: &build-commons |
| 47 | + artifacts: |
| 48 | + name: "build_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}" |
| 49 | + expire_in: 1 hour |
| 50 | + paths: |
| 51 | + - .output/ |
| 52 | + # See https://pnpm.io/continuous-integration#gitlab-ci |
| 53 | + before_script: |
| 54 | + - corepack enable |
| 55 | + - corepack prepare pnpm@latest-8 --activate |
| 56 | + - pnpm config set store-dir .pnpm-store |
| 57 | + script: |
| 58 | + - cd frontend |
| 59 | + - pnpm install --config.platform=linuxmusl --config.architecture=x64 |
| 60 | +# - pnpm lint |
| 61 | + - pnpm build |
| 62 | + |
| 63 | +# =========== |
| 64 | +# SSR STAGING |
| 65 | +# =========== |
| 66 | +ssr_build_develop: |
| 67 | + stage: build |
| 68 | + interruptible: true |
| 69 | + only: |
| 70 | + - merge_requests |
| 71 | + - develop |
| 72 | + except: |
| 73 | + - tags |
| 74 | + - main |
| 75 | + <<: *frontend-cache |
| 76 | + <<: *staging-env |
| 77 | + <<: *build-commons |
| 78 | + |
| 79 | +ssr_docker_develop: |
| 80 | + stage: docker |
| 81 | + only: |
| 82 | + - develop |
| 83 | + image: docker:git |
| 84 | + services: |
| 85 | + - docker:dind |
| 86 | + when: on_success |
| 87 | + <<: *staging-env |
| 88 | + needs: [ "ssr_build_develop" ] |
| 89 | + dependencies: [ "ssr_build_develop" ] |
| 90 | + script: |
| 91 | + - "docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}" |
| 92 | + # App image build |
| 93 | + - "docker build -t ${CI_REGISTRY_IMAGE}/node:develop -f docker/node/Dockerfile ." |
| 94 | + - "docker push ${CI_REGISTRY_IMAGE}/node:develop" |
| 95 | + |
| 96 | +# ======== |
| 97 | +# SSR PROD |
| 98 | +# ======== |
| 99 | +ssr_build_tags: |
| 100 | + stage: build |
| 101 | + interruptible: true |
| 102 | + only: |
| 103 | + - tags |
| 104 | + <<: *frontend-cache |
| 105 | + <<: *production-env |
| 106 | + <<: *build-commons |
| 107 | + |
| 108 | +ssr_docker_tags: |
| 109 | + stage: docker |
| 110 | + only: |
| 111 | + - tags |
| 112 | + image: docker:git |
| 113 | + <<: *production-env |
| 114 | + services: |
| 115 | + - docker:dind |
| 116 | + when: on_success |
| 117 | + needs: [ "ssr_build_tags" ] |
| 118 | + dependencies: [ "ssr_build_tags" ] |
| 119 | + script: |
| 120 | + # Connect to your Gitlab Registry |
| 121 | + - "docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}" |
| 122 | + # App image build |
| 123 | + - "docker build -t ${CI_REGISTRY_IMAGE}/node:latest -t ${CI_REGISTRY_IMAGE}/node:${CI_COMMIT_TAG} -f docker/node/Dockerfile ." |
| 124 | + - "docker push ${CI_REGISTRY_IMAGE}/node:latest" |
| 125 | + - "docker push ${CI_REGISTRY_IMAGE}/node:${CI_COMMIT_TAG}" |
| 126 | + |
| 127 | + |
| 128 | +# ========================================== |
| 129 | +# Create release on Gitlab repository |
| 130 | +# ========================================== |
| 131 | +create_gitlab_release: |
| 132 | + stage: release |
| 133 | + image: registry.gitlab.com/gitlab-org/release-cli:latest |
| 134 | + rules: |
| 135 | + - if: $CI_COMMIT_TAG |
| 136 | + script: |
| 137 | + - echo "Running the release job." |
| 138 | + needs: [ "common_docker_images" ] |
| 139 | + <<: *production-env |
| 140 | + when: on_success |
| 141 | + release: |
| 142 | + tag_name: $CI_COMMIT_TAG |
| 143 | + name: 'Release $CI_COMMIT_TAG' |
| 144 | + description: './CHANGELOG.md' |
0 commit comments