-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
45 lines (41 loc) · 1.1 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
variables:
IMAGE_NAME: korngsamnang/python-demo
IMAGE_TAG: python-app-1.0
stages:
- test
- build
- deploy
run_tests:
stage: test
image: python:3.9-slim-buster
before_script:
- apt-get update && apt-get install -y make
script:
- make test
build_image:
stage: build
image: docker:20.10.16
services:
- docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: '/certs'
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin
script:
- docker build -f build/Dockerfile . -t $IMAGE_NAME:$IMAGE_TAG
- docker push $IMAGE_NAME:$IMAGE_TAG
deploy:
stage: deploy
before_script:
- chmod 400 "$SSH_KEY"
script:
- |
ssh -o StrictHostKeyChecking=no -i "$SSH_KEY" ubuntu@13.229.124.173 "
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" &&
CONTAINERS=\$(docker ps -aq) &&
if [ -n \"\$CONTAINERS\" ]; then
docker stop \$CONTAINERS &&
docker rm \$CONTAINERS;
fi &&
docker run -d -p 5000:5000 $IMAGE_NAME:$IMAGE_TAG
"