Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit e505286

Browse files
committed
Merge branch 'docker_build' into 'master'
Auto-build and push docker image On every push to the master branch, if tests pass, build and publish a new version of the Docker image, with `latest` tag. Additionally, build and publish an image with tag, taken from git, if git push defines a new tag. See merge request postgres-ai/postgres-checkup!303
2 parents ae95301 + 65479a7 commit e505286

File tree

1 file changed

+63
-18
lines changed

1 file changed

+63
-18
lines changed

.gitlab-ci.yml

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@ image: ubuntu:16.04
22

33
stages:
44
- test
5+
- docker_build
56

67
variables:
78
POSTGRES_DB: dbname # set database
89
POSTGRES_USER: username # set username
910
POSTGRES_PASSWORD: ""
1011

11-
before_script:
12-
- apt-get update
13-
- apt-get install -y jq curl wget
14-
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
15-
- echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main $PG_SERVER_VERSION" > /etc/apt/sources.list.d/pgdg.list
16-
- apt-get update
17-
- apt-get -y upgrade
18-
- apt-get -y install golang-1.9-go
19-
- echo "export PATH=\$PATH:/usr/lib/go-1.9/bin" >> ~/.profile
20-
- source ~/.profile
21-
- apt-get -y install postgresql-client-11
22-
- psql --version
12+
.prepare:
13+
stage: test
14+
before_script:
15+
- apt-get update
16+
- apt-get install -y jq curl wget git s3cmd sudo golang-1.9-go
17+
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
18+
- echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main $PG_SERVER_VERSION" > /etc/apt/sources.list.d/pgdg.list
19+
- apt-get update
20+
- apt-get -y upgrade
21+
- apt-get -y install postgresql-client-11
22+
- psql --version
23+
- echo "export PATH=\$PATH:/usr/lib/go-1.9/bin" >> ~/.profile
24+
- source ~/.profile
2325

2426
.test-check:
27+
stage: test
28+
extends: ".prepare"
2529
script:
2630
- psql -h postgres -d dbname -U username -c "SELECT version();"
2731
- echo "Test H003 Non indexed FKs"
@@ -48,20 +52,18 @@ before_script:
4852

4953
test-general:
5054
stage: test
55+
extends: ".prepare"
5156
before_script:
5257
- apt-get update
53-
- apt-get install -y jq curl wget git s3cmd
58+
- apt-get install -y jq curl wget git s3cmd sudo golang-1.9-go
5459
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
5560
- echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main $PG_SERVER_VERSION" > /etc/apt/sources.list.d/pgdg.list
5661
- apt-get update
5762
- apt-get -y upgrade
58-
- apt-get install -y sudo
59-
- apt-get -y install golang-1.9-go
63+
- apt-get -y install postgresql-11 postgresql-contrib-11 postgresql-client-11 postgresql-server-dev-11 && apt-get install -y postgresql-11-pg-stat-kcache
64+
- psql --version
6065
- echo "export PATH=\$PATH:/usr/lib/go-1.9/bin" >> ~/.profile
6166
- source ~/.profile
62-
- apt-get -y install postgresql-11 postgresql-contrib-11 postgresql-client-11
63-
- psql --version
64-
- apt-get install -y postgresql-server-dev-11 && apt-get install -y postgresql-11-pg-stat-kcache
6567
- echo "local all all trust" > /etc/postgresql/11/main/pg_hba.conf
6668
- echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/11/main/pg_hba.conf
6769
- echo "host all all ::1/128 trust" >> /etc/postgresql/11/main/pg_hba.conf
@@ -117,6 +119,7 @@ test-general:
117119

118120
test-pghrep:
119121
stage: test
122+
extends: ".prepare"
120123
script:
121124
- cd pghrep && make test
122125

@@ -142,6 +145,7 @@ test-check-cli:
142145
services:
143146
- postgres:11
144147
stage: "test"
148+
extends: ".prepare"
145149
script: |
146150
errcount=0
147151
printTail=" "
@@ -157,3 +161,44 @@ test-check-cli:
157161
>&2 echo "Oh no! $errcount tests failed"
158162
exit 1
159163
fi
164+
165+
166+
Docker build master:
167+
image: docker:stable
168+
stage: docker_build
169+
when: on_success
170+
variables:
171+
DOCKER_DRIVER: overlay2
172+
DOCKER_HOST: tcp://docker:2375
173+
only:
174+
- master
175+
- docker_build
176+
services:
177+
- docker:dind
178+
before_script:
179+
- docker login -u gitlab-ci-token -p "${CI_BUILD_TOKEN}" registry.gitlab.com
180+
script:
181+
- docker build -t registry.gitlab.com/postgres-ai/postgres-checkup:latest --no-cache=true .
182+
- docker push registry.gitlab.com/postgres-ai/postgres-checkup:latest
183+
after_script:
184+
- docker logout registry.gitlab.com
185+
186+
Docker build for tag:
187+
image: docker:stable
188+
stage: docker_build
189+
when: on_success
190+
variables:
191+
DOCKER_DRIVER: overlay2
192+
DOCKER_HOST: tcp://docker:2375
193+
only:
194+
variables:
195+
- $CI_COMMIT_TAG != null
196+
services:
197+
- docker:dind
198+
before_script:
199+
- docker login -u gitlab-ci-token -p "${CI_BUILD_TOKEN}" registry.gitlab.com
200+
script:
201+
- docker build -t registry.gitlab.com/postgres-ai/postgres-checkup:$CI_COMMIT_TAG --no-cache=true .
202+
- docker push registry.gitlab.com/postgres-ai/postgres-checkup:$CI_COMMIT_TAG
203+
after_script:
204+
- docker logout registry.gitlab.com

0 commit comments

Comments
 (0)