From ce2202bc41f95f83d611880d3e374e3880ba9c8b Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 25 Sep 2021 23:28:04 +0200 Subject: [PATCH] Add deploy job and deploy script --- .gitlab-ci.yml | 16 ++++++++++++++++ Makefile | 8 ++++++-- README.md | 7 +++++++ deploy.sh | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100755 deploy.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e86df46..8cd7dea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ stages: - test-lint-format + - deploy .job_setup: image: python:3.9 @@ -30,3 +31,18 @@ pytest: artifacts: reports: cobertura: coverage.xml + +deploy: + stage: deploy + only: + - develop + before_script: + # https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor + - "command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )" + - eval $(ssh-agent -s) + - echo "${VPS_DEPLOYMENT_PRIVATE_KEY}" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + script: + - echo "Deploying ${CI_COMMIT_BRANCH}:${CI_COMMIT_SHA} ..." + - ssh musicube@${VPS_HOST} -o StrictHostKeyChecking=no -p ${VPS_SSH_PORT} "cd musicube; ./deploy.sh $CI_COMMIT_BRANCH" diff --git a/Makefile b/Makefile index b6afcfd..a74f4fe 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,13 @@ +include docker.env +export $(shell sed 's/=.*//' docker.env) + +SHELL = /bin/bash GIT_COMMIT != git log --pretty=format:'%h' -n 1 + build: - source <(cat docker.env | sed -e 's/^/export /g') docker build \ - --build-arg DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN} \ + --build-arg DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN} \ --build-arg YOUTUBE_COOKIES=${YOUTUBE_COOKIES} \ --build-arg GIT_COMMIT=${GIT_COMMIT} \ -t musicube:${GIT_COMMIT} -t musicube:latest \ diff --git a/README.md b/README.md index bda0477..fa4a53e 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,13 @@ Requirements: ``` $ docker --version Docker version 20.10.8, build 3967b7d28e +$ make --version +GNU Make 4.3 +Built for x86_64-pc-linux-gnu +Copyright (C) 1988-2020 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. ``` Build image: diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..d4e9bad --- /dev/null +++ b/deploy.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +BRANCH="$1" + +# Exit immediately if a command fails +set -e +# Log every command +set -x + +git status +git fetch +git checkout "$BRANCH" +git pull --ff-only +make build +docker stop musicube || true +docker run --rm --detach --name musicube musicube