Added CI Deployment

This commit is contained in:
Matthew McKinnon 2023-12-31 20:09:37 +10:00
parent c6e8a38eee
commit 087c16521c
2 changed files with 41 additions and 5 deletions

View File

@ -33,6 +33,38 @@ docker_build:
only: only:
- master - master
docker_deploy:
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
stage: docker_deploy
image: kroniak/ssh-client:3.6
script:
- mkdir ~/.ssh
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# log into Docker registry
- ssh administrator@docker.comprofix.xyz "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY"
# stop container, remove image.
- ssh administrator@docker.comprofix.xyz "docker stop comprofix" || true
- ssh administrator@docker.comprofix.xyz "docker rm comprofix" || true
- ssh administrator@docker.comprofix.xyz "docker rmi registry.gitlab.comprofix.com/comprofix/website:latest" || true
# start new container
- ssh administrator@docker.comprofix.xyz "docker run -d \
--name=comprofix \
--network=traefik \
--restart unless-stopped \
--label traefik.enable=true
--label traefik.http.routers.{{container_name}}.rule=Host(`comprofix.com`) \
--label traefik.http.routers.{{container_name}}.rule=Host(`www.comprofix.com`) \
--label traefik.http.routers.{{container_name}}.entrypoints=https \
--label traefik.http.routers.{{container_name}}.tls.certresolver=cloudflare \
registry.gitlab.comprofix.com/comprofix/website:latest"
only:
- tags

View File

@ -5,9 +5,13 @@ services:
container_name: comprofix container_name: comprofix
image: registry.gitlab.comprofix.com/comprofix/website:latest image: registry.gitlab.comprofix.com/comprofix/website:latest
restart: unless-stopped restart: unless-stopped
recreate: true
networks: networks:
- npm_default - name: traefik
labels:
traefik.enable=true
traefik.http.routers.{{container_name}}.rule=Host(`comprofix.com`)
traefik.http.routers.{{container_name}}.rule=Host(`www.comprofix.com`)
traefik.http.routers.{{container_name}}.entrypoints=https
traefik.http.routers.{{container_name}}.tls.certresolver=cloudflare
networks:
npm_default:
external: true