updated ci/cd with prod deploy

This commit is contained in:
Solomon Laing 2021-06-13 17:38:34 +09:30
parent e1efdd3de1
commit 681838a33e
4 changed files with 24 additions and 26 deletions

View File

@ -3,6 +3,7 @@ image: docker:20.10.5
stages: stages:
- build - build
- push - push
- deploy
before_script: before_script:
- echo -n $CI_REGISTRY_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY - echo -n $CI_REGISTRY_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
@ -39,3 +40,21 @@ push tag:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
deploy:
stage: deploy
tags:
- docker
environment:
name: Production
url: "$Live_Server_IP"
when: manual
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y)'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
script:
- ssh -J "$Live_Server_User"@"$Live_Server_IP" "$Live_Server_User"@"$Live_Server_Target" "echo -e 'dev:\n image: \'$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA\'\n restart: always\n ports:\n - \'8090:5000\'\n only:\n - master' > docker-compose.yml && docker-compose up -d --remove-orphans --force-recreate"

View File

@ -1,14 +0,0 @@
version: '3.4'
services:
simpleblogapi:
image: simpleblogapi
build:
context: .
dockerfile: ./Dockerfile
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5000"]
ports:
- 5000:5000
- 5678:5678
environment:
- FLASK_APP=dev.py

View File

@ -1,11 +0,0 @@
version: '3.4'
services:
simpleblogapi:
image: simpleblogapi
build:
context: .
dockerfile: ./Dockerfile
ports:
- 5000:5000
tty: true

View File

@ -13,3 +13,7 @@ I'm *hoping* that this works.
You can also have code inline like `this`. You can also have code inline like `this`.
[Here](https://www.example.com) is a link for good measure. [Here](https://www.example.com) is a link for good measure.
## Image test
<img alt="My odroid MC1 and N2 cluster" src="https://gitlab.inkletblot.com/inkletblot/simple-blog-api/-/raw/master/assets/odroid-cluster-2.jpg" style="max-height: 400px;" />