Skip to content

Instantly share code, notes, and snippets.

@LasaleFamine
Created June 21, 2020 21:44
Show Gist options
  • Select an option

  • Save LasaleFamine/68f5a0630a22c1b94cd20947e90be9d8 to your computer and use it in GitHub Desktop.

Select an option

Save LasaleFamine/68f5a0630a22c1b94cd20947e90be9d8 to your computer and use it in GitHub Desktop.
stages:
- test
- build
- deploy
# Prepare the variables we will use on different stages
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:latest
IMAGE_TAG_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
SSH_ENTRY: userforvps@yourDigitalOceanVps.com
# NOTE: make sure this folder is already present on the VPS
DEPLOY_DIR: /home/userforvps/strapi
test:
interruptible: true
image: node:latest
stage: test
script:
- yarn
- yarn test
build:
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
stage: build
script:
- docker build --cache-from $IMAGE_TAG --tag $IMAGE_TAG_SHA --tag $IMAGE_TAG --build-arg POSTGRES_PASSWORD=${POSTGRES_PASSWORD} --build-arg POSTGRES_USER=${POSTGRES_USER} .
- docker push $IMAGE_TAG
- docker push $IMAGE_TAG_SHA
only:
- tags
deploy:
image: alpine
stage: deploy
environment:
name: production
url: https://strapi.yourdomain.com
before_script:
- apk add --no-cache rsync openssh
- mkdir -p ~/.ssh
- echo "$SECRET_SSH" >> ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- ./ci/replace-image-name.sh $IMAGE_TAG_SHA
- echo "docker login registry.gitlab.com -u $DEPLOY_USER -p $DEPLOY_PASSWORD" > ci/remote-login.sh
- rsync -avz -e 'ssh -p 22' docker-compose.yml $SSH_ENTRY:$DEPLOY_DIR
- rsync -avz -e 'ssh -p 22' ci/remote-login.sh $SSH_ENTRY:$DEPLOY_DIR
script: >
ssh $SSH_ENTRY -p 22 bash -c '
docker-compose version &&
cd strapi &&
./remote-login.sh &&
docker-compose pull &&
docker-compose down &&
docker-compose up -d '
only:
- tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment