-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitbucket-pipelines.yml
75 lines (65 loc) · 3.19 KB
/
bitbucket-pipelines.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
image: markhobson/maven-chrome
# enabling docker
options:
docker: true
pipelines:
default:
- step:
name: Run Maven
caches:
- maven
script:
- mvn -B verify # -B batch mode makes Maven less verbose
artifacts:
- target/**
branches:
master:
- step:
name: Run Maven
caches:
- maven
script:
- mvn -B verify # -B batch mode makes Maven less verbose
artifacts:
- target/**
- step:
name: Build Docker Image
script:
- export IMAGE_LATEST=$REGISTRY_DOMAIN/$REGISTRY_NAME/$APPNAME:latest
- export REPOSITORY_NAME=$REGISTRY_DOMAIN/$REGISTRY_NAME/$APPNAME
- export IMAGE_CURRENT=$REPOSITORY_NAME:$BITBUCKET_COMMIT
# build and push image to docker registry
- docker login -u $REGISTRY_NAME -p $REGISTRY_PASSWORD $REGISTRY_DOMAIN
- docker build -t $IMAGE_CURRENT -t $REPOSITORY_NAME .
- docker push $IMAGE_CURRENT
- docker push $IMAGE_LATEST
- docker logout
- step:
name: Deploy to PaaS
deployment: test
script:
- export IMAGE_LATEST=$REGISTRY_DOMAIN/$REGISTRY_NAME/$APPNAME:latest
# creating tls certificate files from secrets
# write authority certificate
- echo "-----BEGIN CERTIFICATE-----" > ca-cert.pem
- echo $DOCKER_CA_CERT >> ca-cert.pem
- echo "-----END CERTIFICATE-----" >> ca-cert.pem
# write tls certificate
- echo "-----BEGIN CERTIFICATE-----" > server-cert.pem
- echo $DOCKER_SERVER_CERT >> server-cert.pem
- echo "-----END CERTIFICATE-----" >> server-cert.pem
# write tls key
- echo "-----BEGIN RSA PRIVATE KEY-----" > server-key.pem
- echo $DOCKER_SERVER_KEY >> server-key.pem
- echo "-----END RSA PRIVATE KEY-----" >> server-key.pem
# finished writing
# log remote docker host into registry
- docker -H $DOCKER_SERVER_ADDRESS --tls --tlscacert='ca-cert.pem' --tlscert='server-cert.pem' --tlskey='server-key.pem' login -u $REGISTRY_NAME -p $REGISTRY_PASSWORD $REGISTRY_DOMAIN
# pull latest image
- docker -H $DOCKER_SERVER_ADDRESS --tls --tlscacert='ca-cert.pem' --tlscert='server-cert.pem' --tlskey='server-key.pem' pull $IMAGE_LATEST
# logout remote docker host from registry
- docker -H $DOCKER_SERVER_ADDRESS --tls --tlscacert='ca-cert.pem' --tlscert='server-cert.pem' --tlskey='server-key.pem' logout
# stop and remove old container if exists
- docker -H $DOCKER_SERVER_ADDRESS --tls --tlscacert='ca-cert.pem' --tlscert='server-cert.pem' --tlskey='server-key.pem' rm -f $APPNAME || true
# start new container with ssl certificate
- docker -H $DOCKER_SERVER_ADDRESS --tls --tlscacert='ca-cert.pem' --tlscert='server-cert.pem' --tlskey='server-key.pem' run -d -e VIRTUAL_HOST=$APPNAME.cm.tm.kit.edu -e LETSENCRYPT_HOST=$APPNAME.cm.tm.kit.edu -e [email protected] --name $APPNAME --restart=always $IMAGE_LATEST