forked from JetBrains/teamcity-azure-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud-config.yaml
165 lines (153 loc) · 6.45 KB
/
cloud-config.yaml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#cloud-config
write_files:
- path: "/etc/teamcity/update.sh"
permissions: 0755
content: |
#!/bin/bash
while true
do
STATUS=$(curl -s -o /etc/teamcity/tags -w '%{http_code}' -H Metadata:true "http://169.254.169.254/metadata/instance/compute/tags?api-version=2017-08-01&format=text")
if [ $STATUS -eq 200 ]; then
VERSION=$(cat /etc/teamcity/tags | sed -n 's/.*teamcity-version\:\([^;]\+\).*/\1/p')
if [[ ! -z "$VERSION" ]]; then
TEAMCITY_VERSION="TEAMCITY_VERSION=$VERSION"
CURRENT_VERSION=$(cat /etc/teamcity/version)
if [ "$TEAMCITY_VERSION" != "$CURRENT_VERSION" ]; then
echo "TeamCity version has changed to $VERSION"
echo "$TEAMCITY_VERSION" > /etc/teamcity/version
/usr/bin/docker pull jetbrains/teamcity-server:${VERSION}
systemctl restart teamcity-server.service
/usr/bin/docker pull jetbrains/teamcity-agent:${VERSION}
systemctl restart teamcity-agent.service
fi
fi
fi
sleep 60
done
- path: "/etc/coreos/update.conf"
content: |
REBOOT_STRATEGY="off"
coreos:
units:
- name: "format-mnt-data.service"
enable: true
content: |
[Unit]
Requires=network-online.target
Before=teamcity-server.service mnt-data.mount
ConditionPathExists=!/dev/mapper/app-data
[Service]
Type=oneshot
ExecStart=/bin/bash -c \
'/usr/sbin/pvcreate /dev/sdc && \
/usr/sbin/vgcreate app /dev/sdc && \
/usr/sbin/lvcreate -l 100%FREE -n data app && \
/usr/sbin/mkfs.ext4 /dev/mapper/app-data'
[Install]
WantedBy=multi-user.target
- name: "mnt-data.mount"
enable: true
content: |
[Unit]
Before=teamcity-server.service
After=format-mnt-data.service
Requires=format-mnt-data.service
ConditionVirtualization=!container
Conflicts=umount.target
[Mount]
What=/dev/mapper/app-data
Where=/mnt/data
Type=ext4
Options=
[Install]
RequiredBy=teamcity-server.service
- name: "get-mysql-connector.service"
enable: true
content: |
[Unit]
Before=teamcity-server.service
After=mnt-data.mount
Requires=mnt-data.mount
ConditionPathExists=!/mnt/data/teamcity/lib/jdbc/mysql-connector-java-bin.jar
[Service]
Type=oneshot
ExecStart=/usr/bin/mkdir -p /mnt/data/teamcity/lib/jdbc
ExecStart=/usr/bin/wget -O /mnt/data/teamcity/lib/jdbc/mysql-connector-java-bin.jar \
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar
[Install]
WantedBy=multi-user.target
- name: "prepare-db-properties.service"
enable: true
content: |
[Unit]
Before=teamcity-server.service
After=mnt-data.mount
Requires=mnt-data.mount network-online.target
ConditionPathExists=!/mnt/data/teamcity/config/database.properties
[Service]
Type=oneshot
ExecStart=/usr/bin/mkdir -p /mnt/data/teamcity/config
ExecStart=/bin/bash -c 'echo connectionProperties.user=teamcity@%RDSHost% > /mnt/data/teamcity/config/database.properties'
ExecStart=/bin/bash -c 'echo connectionProperties.password=%RDSPassword% >> /mnt/data/teamcity/config/database.properties'
ExecStart=/bin/bash -c 'echo connectionUrl=jdbc\\:mysql\\://%RDSHost%.mysql.database.azure.com/%RDSDataBase%?autoReconnect=true >> /mnt/data/teamcity/config/database.properties'
[Install]
WantedBy=multi-user.target
- name: "teamcity-update.service"
command: "start"
content: |
[Unit]
After=docker.service
Before=teamcity-server.service teamcity-agent.service
Requires=docker.service network-online.target
[Service]
ExecStart=+/bin/sh /etc/teamcity/update.sh
Restart=always
[Install]
WantedBy=multi-user.target
- name: "teamcity-server.service"
command: "start"
content: |
[Unit]
Description=TeamCity Server
After=docker.service mnt-data.mount get-mysql-connector.service prepare-db-properties.service teamcity-update.service
Requires=docker.service mnt-data.mount get-mysql-connector.service prepare-db-properties.service teamcity-update.service
[Service]
EnvironmentFile=/etc/teamcity/version
TimeoutStartSec=1200s
ExecStartPre=/bin/sh -c "docker images --filter 'before=jetbrains/teamcity-server:${TEAMCITY_VERSION}' --format '{{.ID}} {{.Repository}}' | grep 'jetbrains/teamcity-server' | grep -Eo '^[^ ]+' | xargs -r docker rmi"
ExecStart=/usr/bin/docker run \
-v /mnt/data/teamcity:/data/teamcity_server/datadir \
-v /mnt/data/logs/teamcity:/opt/teamcity/logs \
-v /mnt/data/temp/teamcity:/opt/teamcity/temp \
-p 80:8111 \
--name teamcity-server \
jetbrains/teamcity-server:${TEAMCITY_VERSION}
ExecStop=-/usr/bin/docker exec teamcity-server /opt/teamcity/bin/teamcity-server.sh stop 60
ExecStopPost=-/usr/bin/docker stop teamcity-server
ExecStopPost=-/usr/bin/docker rm teamcity-server
Restart=always
[Install]
WantedBy=multi-user.target
- name: "teamcity-agent.service"
command: "start"
content: |
[Unit]
Description=TeamCity Agent
After=teamcity-server.service coreos-metadata.service teamcity-update.service
Requires=teamcity-server.service coreos-metadata.service teamcity-update.service
[Service]
EnvironmentFile=/etc/teamcity/version
TimeoutStartSec=1200s
EnvironmentFile=/run/metadata/coreos
ExecStartPre=/bin/sh -c "docker images --filter 'before=jetbrains/teamcity-agent:${TEAMCITY_VERSION}' --format '{{.ID}} {{.Repository}}' | grep 'jetbrains/teamcity-agent' | grep -Eo '^[^ ]+' | xargs -r docker rmi"
ExecStart=/usr/bin/docker run \
-v /mnt/data/temp/teamcity:/opt/teamcity/temp \
-e SERVER_URL=${COREOS_AZURE_IPV4_DYNAMIC} \
-e AGENT_NAME=Default \
--name teamcity-agent \
jetbrains/teamcity-agent:${TEAMCITY_VERSION}
ExecStop=-/usr/bin/docker stop teamcity-agent
ExecStopPost=-/usr/bin/docker rm teamcity-agent
Restart=always
[Install]
WantedBy=multi-user.target