-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
48 lines (45 loc) · 1.79 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
variables:
DOCKER_DRIVER: overlay2
build-api:
stage: build
image: docker:latest
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build -t "$CI_REGISTRY_IMAGE:latest" . -f Dockerfile
- docker push "$CI_REGISTRY_IMAGE:latest"
deploy:staging:
stage: deploy
image: gitlab/dind:latest
only:
- "master"
environment:
name: staging
url: https://ipaddr.staging.kristianjones.dev
before_script:
- mkdir -p ~/.ssh
- echo "$STAGING_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H $STAGING_SERVER_IP >> ~/.ssh/known_hosts
script:
- ssh root@$STAGING_SERVER_IP "cd /root/Staging; docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}; docker-compose stop ${STAGING_SERVER_CONTAINER}; docker-compose rm --force ${STAGING_SERVER_CONTAINER}; docker-compose pull ${STAGING_SERVER_CONTAINER}; docker-compose up -d ${STAGING_SERVER_CONTAINER}"
deploy:production:
stage: deploy
only:
- "master"
when: manual
image: gitlab/dind:latest
environment:
name: production
url: https://ipaddr.network
before_script:
- mkdir -p ~/.ssh
- echo "$PROD_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H $PROD_SERVER_IP >> ~/.ssh/known_hosts
script:
- ssh root@$PROD_SERVER_IP "cd /root/KristianJones; docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}; docker-compose stop ${PROD_SERVER_CONTAINER}; docker-compose rm --force ${PROD_SERVER_CONTAINER}; docker-compose pull ${PROD_SERVER_CONTAINER}; docker-compose up -d ${PROD_SERVER_CONTAINER}"