Merge branch '5-cd' into 'develop'

Add deploy job and script

Closes #5

See merge request ekzyis/musicube!12
This commit is contained in:
Ramdip Gill 2021-09-25 23:17:02 +00:00
commit d363960426
4 changed files with 45 additions and 2 deletions

View File

@ -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"

View File

@ -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 \

View File

@ -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 <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
```
Build image:

16
deploy.sh Executable file
View File

@ -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