Skip to content

Commit

Permalink
ci: Use semaphore to promote to production
Browse files Browse the repository at this point in the history
#122: Deploy to separate GCP project
  • Loading branch information
MichaelAkvo committed Apr 14, 2022
1 parent 67849ab commit 1edd439
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
29 changes: 29 additions & 0 deletions .semaphore/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
version: v1.0
name: ISCO promotion
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
global_job_config:
secrets:
- name: isco
prologue:
commands:
- checkout
- export CI_COMMIT="${SEMAPHORE_GIT_SHA:0:7}"
- export CI_BRANCH="${SEMAPHORE_GIT_BRANCH}"
- export CI_TAG="${SEMAPHORE_GIT_TAG_NAME}"
- export CI_PULL_REQUEST="${SEMAPHORE_GIT_REF_TYPE/pull-request/true}"
- export CI_COMMIT_RANGE="${SEMAPHORE_GIT_COMMIT_RANGE}"
- export CLOUDSDK_CORE_DISABLE_PROMPTS=1
- export PROD_DEPLOY=1
blocks:
- name: 'Promotion'
task:
jobs:
- name: Promote to production
run:
when: "branch = 'main'"
commands:
- ./ci/deploy.sh
12 changes: 3 additions & 9 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ global_job_config:
- export COVERALLS_REPO_TOKEN="${COVERALLS_ISCO_TOKEN}"
blocks:
- name: 'Build, Test & Deploy'
skip:
when: "tag =~ '.*'"
task:
prologue:
commands:
Expand All @@ -48,11 +46,7 @@ blocks:
commands:
- ./ci/build.sh
- ./ci/deploy.sh

promotions:
- name: "Promote to production"
run:
when: "tag =~ '.*'"
task:
jobs:
- name: Promote to production
commands:
- ./ci/deploy.sh
pipeline_file: prod.yml
16 changes: 7 additions & 9 deletions ci/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash

# The required env vars require a registry_prefix depending on the deploy environment:
# prod: PROD_
# test: TEST_
Expand All @@ -13,14 +12,13 @@
# GCP_DOCKER_HOST - Where to push the docker images to
# GCP_SERVICE_ACCOUNT_FILE - path to file containing GCP service account credentials
# IMAGE_PREFIX - The host (and path if necessary) to push the docker images to
#
# Optional env vars:
# PROD_DEPLOY - Make this a deployment to production
set -exuo pipefail

#[[ "${CI_BRANCH}" != "main" && ! "${CI_TAG:=}" =~ promote.* ]] && { echo "Branch different than main and not a tag. Skip deploy"; exit 0; }
#[[ "${CI_PULL_REQUEST:-}" == "true" ]] && { echo "Pull request. Skip deploy"; exit 0; }

if [[ "${CI_TAG:=}" =~ promote.* ]]; then
PROD_DEPLOY=1
fi
[[ "${CI_BRANCH}" != "main" ]] && { echo "Branch must be 'main' to deploy"; exit 0; }
[[ "${CI_PULL_REQUEST:-}" == "true" ]] && { echo "Pull request. Skip deploy"; exit 0; }

export CLOUDSDK_CONTAINER_USE_CLIENT_CERTIFICATE=False

Expand Down Expand Up @@ -74,7 +72,7 @@ apply_deployment () {
}

set +x # Disable printing the variable values; values might be secret
if [[ -n "${PROD_DEPLOY:=}" ]] ; then
if [[ -n "${PROD_DEPLOY:-}" ]] ; then
generate_vars "PROD"
else
generate_vars "TEST"
Expand All @@ -83,7 +81,7 @@ set -x # Renable it

auth

if [[ -z "${CI_TAG:=}" ]]; then
if [[ -z "${PROD_DEPLOY:-}" ]] ; then
push_image backend
push_image frontend
fi
Expand Down
20 changes: 0 additions & 20 deletions ci/promote-test-to-prod.sh

This file was deleted.

0 comments on commit 1edd439

Please sign in to comment.