-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
128 lines (117 loc) · 3.7 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
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
variables:
BRANCH_NAME: "$CI_COMMIT_REF_NAME"
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
CONTAINER_CI_IMAGE: $CI_REGISTRY_IMAGE/ci:latest
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-test
CONTAINER_PRODUCTION_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
image:
name: linuxserver/docker-compose:2.15.0-v2
entrypoint: ["/bin/sh", "-c"]
services:
- name: docker:24.0-dind
stages:
- build
- test
- release
.gitlab-registry-before_script: &gitlab-registry-before_script
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.release-requirements: &release-requirements
only:
refs:
- main
- tags
build-test:
stage: build
<<: *gitlab-registry-before_script
script:
- export RAILS_MASTER_KEY_TEST="$RAILS_MASTER_KEY_TEST"
- docker build
--cache-from $CONTAINER_TEST_IMAGE
--pull
-t $CONTAINER_TEST_IMAGE
--secret id=RAILS_MASTER_KEY_SECRET,env=RAILS_MASTER_KEY_TEST
--build-arg BUILDKIT_INLINE_CACHE=1
--build-arg TARGET_RAILS_ENV="test"
--build-arg RAILS_MASTER_KEY=$RAILS_MASTER_KEY_TEST
-f Dockerfile.production
"."
- docker push $CONTAINER_TEST_IMAGE
build-production:
stage: build
<<: *gitlab-registry-before_script
script:
- export RAILS_MASTER_KEY_PROD="$RAILS_MASTER_KEY_PROD"
- docker build
--cache-from $CONTAINER_TEST_IMAGE
--pull
-t $CONTAINER_PRODUCTION_IMAGE
--secret id=RAILS_MASTER_KEY_SECRET,env=RAILS_MASTER_KEY_PROD
--build-arg BUILDKIT_INLINE_CACHE=1
--build-arg TARGET_RAILS_ENV="production"
--build-arg RAILS_MASTER_KEY=$RAILS_MASTER_KEY_PROD
-f Dockerfile.production
"."
- docker push $CONTAINER_PRODUCTION_IMAGE
<<: *release-requirements
build-ci:
stage: build
<<: *gitlab-registry-before_script
script:
- docker compose up -d postgres
- docker build
--cache-from $CONTAINER_CI_IMAGE
--pull
-t $CONTAINER_CI_IMAGE
-f Dockerfile.ci
--build-arg BUILDKIT_INLINE_CACHE=1
"."
- docker push $CONTAINER_CI_IMAGE
only:
refs:
- main
- tags
changes:
- Dockerfile.ci
test-rails:
stage: test
<<: *gitlab-registry-before_script
script:
- export RAILS_MASTER_KEY="$RAILS_MASTER_KEY_TEST"
- export RAILS_ENV="test"
- docker pull $CONTAINER_TEST_IMAGE
- docker compose up -d postgres
- free -h
# - bin/wait-for-it.sh -t 15 localhost:5432 -- docker compose logs postgres
# Prepare the database; since we can't mount a volume on the service
# HOST is set via RAILS_ENV, in docker-compose, which is set to test
# also set explicitly above
- docker compose run
-e POSTGRES_USER="postgres"
-e POSTGRES_DB="postgres"
-e POSTGRES_PASSWORD="postgres"
rails-test
./.dockerdev/postgresql/docker-entrypoint-initdb.d/init-user-db.sh
postgres
- docker compose run rails-test bundle
- docker compose run
-e RELAUNCH_COMMUNITY_DATABASE_HOST="postgres"
rails-test rails db:create
- docker compose run
-e RELAUNCH_COMMUNITY_DATABASE_HOST="postgres"
rails-test rails db:test:prepare
- docker compose run
-e RELAUNCH_COMMUNITY_DATABASE_HOST="postgres"
rails-test
release-rails-image:
stage: release
<<: *gitlab-registry-before_script
script:
- docker pull $CONTAINER_PRODUCTION_IMAGE
- docker tag $CONTAINER_PRODUCTION_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
<<: *release-requirements
# TODO: depending on CDN performance, consider compiling and pushing assets AoT