-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
107 lines (100 loc) · 3.26 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
default:
image: docker:20.10.16
services:
- docker:20.10.16-dind
before_script:
- apk add --no-cache make bash python3 ncurses openssh-client-common
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
stages:
- build
- release
- deploy
variables:
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
CONTAINER_BACKEND_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/backend:latest
CONTAINER_FRONTEND_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/frontend:latest
build-backend:
stage: build
script:
- cd backend
- make build-image
- docker push $CI_REGISTRY/Marlopes10/intranet-trems/backend:latest
build-frontend:
stage: build
script:
- cd frontend
- make build-image
- docker push $CI_REGISTRY/Marlopes10/intranet-trems/frontend:latest
release-image-backend:
stage: release
script:
- docker pull $CI_REGISTRY/Marlopes10/intranet-trems/backend:latest
- docker tag $CI_REGISTRY/Marlopes10/intranet-trems/backend $CONTAINER_BACKEND_RELEASE_IMAGE
- docker push $CI_REGISTRY/Marlopes10/intranet-trems/backend:latest
only:
- main
release-image-frontend:
stage: release
script:
- docker $CI_REGISTRY/Marlopes10/intranet-trems/frontend:latest
- docker tag $CI_REGISTRY/Marlopes10/intranet-trems/frontend $CONTAINER_FRONTEND_RELEASE_IMAGE
- docker push $CI_REGISTRY/Marlopes10/intranet-trems/frontend:latest
only:
- main
deploy:
stage: deploy
# when: manual
script:
- mkdir -p ~/.ssh/
- touch ~/.ssh/known_hosts
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- cd devops
- eval `ssh-agent -s`
- echo "${DEPLOY_SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add - > /dev/null # add ssh key
- export TERM=dumb
- touch .env
- 'echo "DEPLOY_ENV: ${DEPLOY_ENV}" >> .env'
- 'echo "DEPLOY_HOST: ${DEPLOY_HOST}" >> .env'
- 'echo "DEPLOY_PORT: ${DEPLOY_PORT}" >> .env'
- 'echo "DEPLOY_USER: ${DEPLOY_USER}" >> .env'
- 'echo "DOCKER_CONFIG: ${DOCKER_CONFIG}" >> .env'
- 'echo "STACK_NAME: ${STACK_NAME}" >> .env'
- make docker-setup
- make stack-deploy
only:
- main
environment: production
# deploy-with-auxiliary-docker-image:
# stage: deploy
# variables:
# REGISTRY: ${CI_REGISTRY}
# USERNAME: ${CI_REGISTRY_USER}
# PASSWORD: ${CI_REGISTRY_PASSWORD}
# REMOTE_HOST: ${DEPLOY_HOST}
# REMOTE_PORT: ${DEPLOY_PORT}
# REMOTE_USER: ${DEPLOY_USER}
# REMOTE_PRIVATE_KEY: "${DEPLOY_SSH_PRIVATE_KEY}"
# STACK_FILE: devops/stacks/${DEPLOY_HOST}.yml
# STACK_NAME: ${STACK_NAME}
# DEPLOY_IMAGE: ghcr.io/kitconcept/docker-stack-deploy:latest
# script:
# - docker pull ${DEPLOY_IMAGE}
# - docker run --rm
# -v "$(pwd)":/github/workspace
# -v /var/run/docker.sock:/var/run/docker.sock
# -e REGISTRY=${REGISTRY}
# -e USERNAME=${USERNAME}
# -e PASSWORD=${PASSWORD}
# -e REMOTE_HOST=${REMOTE_HOST}
# -e REMOTE_PORT=${REMOTE_PORT}
# -e REMOTE_USER=${REMOTE_USER}
# -e REMOTE_PRIVATE_KEY="${REMOTE_PRIVATE_KEY}"
# -e STACK_FILE=${STACK_FILE}
# -e STACK_NAME=${STACK_NAME}
# ${DEPLOY_IMAGE}
# only:
# - main
# environment: production