|
| 1 | +# NOTE: keep in mind this file is _included_ by _other_ repos, and thus the env var names |
| 2 | +# are not _always_ related to _this_ repo ;-) |
| 3 | + |
| 4 | +# A GitLab group (ideally) or project that wants to deploy to a nomad cluster, |
| 5 | +# will need to set [Settings] [CI/CD] [Variables] |
| 6 | +# NOMAD_ADDR |
| 7 | +# NOMAD_TOKEN |
| 8 | +# to whatever your Nomad cluster was setup to. |
| 9 | + |
| 10 | + |
| 11 | +# NOTE: very first pipeline, the [build] below will make sure this is created |
| 12 | +image: registry.gitlab.com/internetarchive/nomad/master |
| 13 | + |
| 14 | +stages: |
| 15 | + - build |
| 16 | + - test |
| 17 | + - deploy |
| 18 | + - cleanup |
| 19 | + |
| 20 | +build: |
| 21 | + # Tracey 3/2024: |
| 22 | + # This was adapted & simplified from: |
| 23 | + # https://gitlab.com/gitlab-org/gitlab/-/raw/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml |
| 24 | + stage: build |
| 25 | + # If need to rebuild this image while runners are down, `cd` to this directory, then, as root: |
| 26 | + # podman login registry.gitlab.com |
| 27 | + # podman build --net=host --tag registry.gitlab.com/internetarchive/nomad/master . && sudo podman push registry.gitlab.com/internetarchive/nomad/master |
| 28 | + image: registry.gitlab.com/internetarchive/nomad/master |
| 29 | + variables: |
| 30 | + DOCKER_HOST: 'unix:///run/podman/podman.sock' |
| 31 | + DOCKER_TLS_CERTDIR: '' |
| 32 | + DOCKER_BUILDKIT: 1 |
| 33 | + script: |
| 34 | + - /build.sh |
| 35 | + artifacts: |
| 36 | + reports: |
| 37 | + dotenv: gl-auto-build-variables.env |
| 38 | + rules: |
| 39 | + - if: '$BUILD_DISABLED' |
| 40 | + when: never |
| 41 | + - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' |
| 42 | + |
| 43 | +test-ourself: |
| 44 | + stage: test |
| 45 | + image: ${CI_REGISTRY_IMAGE}/${CI_COMMIT_REF_SLUG}:${CI_COMMIT_SHA} |
| 46 | + script: |
| 47 | + - env -i zsh -euax test/test.sh |
| 48 | + rules: |
| 49 | + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' |
| 50 | + when: never |
| 51 | + - if: '$CI_PROJECT_PATH_SLUG == "internetarchive-nomad"' |
| 52 | + |
| 53 | +deploy: |
| 54 | + stage: deploy |
| 55 | + script: |
| 56 | + # https://gitlab.com/internetarchive/nomad/-/blob/master/deploy.sh |
| 57 | + - /deploy.sh |
| 58 | + environment: |
| 59 | + name: $CI_COMMIT_REF_SLUG |
| 60 | + url: https://$HOSTNAME |
| 61 | + on_stop: stop_review |
| 62 | + rules: |
| 63 | + - if: '$NOMAD_VAR_NO_DEPLOY' |
| 64 | + when: never |
| 65 | + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' |
| 66 | + when: never |
| 67 | + - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' |
| 68 | + |
| 69 | +deploy-serverless: |
| 70 | + stage: deploy |
| 71 | + script: |
| 72 | + - | |
| 73 | + if [[ -n "$CI_REGISTRY" && -n "$CI_REGISTRY_USER" ]]; then |
| 74 | + echo "Logging in to GitLab Container Registry with CI credentials..." |
| 75 | +
|
| 76 | + # this filters stderr of `podman login`, w/o merging stdout & stderr together |
| 77 | + set +x |
| 78 | + { echo "$CI_REGISTRY_PASSWORD" | podman --remote login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY" 2>&1 1>&3 | ( grep -E -v "^WARNING! Your password will be stored unencrypted in |^Configure a credential helper to remove this warning. See|^https://docs.docker.com/engine/reference/commandline/login/#credentials-store" || true ) 1>&2; } 3>&1 |
| 79 | + fi |
| 80 | +
|
| 81 | + set -x |
| 82 | + image_tagged="$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA" |
| 83 | + image_latest="$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest" |
| 84 | + podman --remote tag $image_tagged $image_latest |
| 85 | + podman --remote push $image_latest |
| 86 | + rules: |
| 87 | + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' |
| 88 | + when: never |
| 89 | + - if: '$CI_COMMIT_BRANCH && $NOMAD_VAR_SERVERLESS' |
| 90 | + |
| 91 | + |
| 92 | +stop_review: |
| 93 | + # See: |
| 94 | + # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml |
| 95 | + stage: cleanup |
| 96 | + variables: |
| 97 | + GIT_STRATEGY: none |
| 98 | + script: |
| 99 | + - /deploy.sh stop |
| 100 | + environment: |
| 101 | + name: $CI_COMMIT_REF_SLUG |
| 102 | + action: stop |
| 103 | + dependencies: [] |
| 104 | + allow_failure: true |
| 105 | + rules: |
| 106 | + - if: '$CI_COMMIT_BRANCH == "main"' |
| 107 | + when: never |
| 108 | + - if: '$CI_COMMIT_BRANCH == "master"' |
| 109 | + when: never |
| 110 | + - if: '$NOMAD_VAR_NO_DEPLOY' |
| 111 | + when: never |
| 112 | + - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' |
| 113 | + when: manual |
0 commit comments