-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
54 lines (46 loc) · 1.25 KB
/
.gitlab-ci.yml
File metadata and controls
54 lines (46 loc) · 1.25 KB
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
image: docker:stable
services:
- docker:dind
stages:
- build
- deploy
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
before_script:
- 'which ssh-agent || ( apk update && apk add openssh-client )'
- docker info
.build-env: &build-env
stage: build
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- echo $DOCKER_IMAGE
- docker pull $DOCKER_IMAGE || true
- docker build --cache-from $DOCKER_IMAGE --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $DOCKER_IMAGE .
- docker push $DOCKER_IMAGE
build-dev:
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE:latest
<<: *build-env
only:
- dev
build-tags:
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
<<: *build-env
only:
- tags
deploy:
stage: deploy
script:
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_DEV_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- echo "$SSH_DEV_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ssh ${DEV_CICDUSER}@${DEV_SERVER} 'bash -s' < ./deploy.sh
- rm -rf ~/.ssh
only:
- dev