-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.yml
169 lines (166 loc) · 5.76 KB
/
config.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
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
166
167
168
169
version: 2.1
orbs:
ruby: circleci/[email protected]
node: circleci/[email protected]
docker: circleci/[email protected]
kubernetes: circleci/[email protected]
browser-tools: circleci/[email protected]
workflows:
version: 2
test_build_deploy:
jobs:
- test
- build:
requires:
- test
filters:
branches:
only: main
- deploy:
requires:
- test
- build
filters:
branches:
only: main
jobs:
test:
docker:
- image: cimg/ruby:3.2.3-browsers
- image: cimg/postgres:13.7
environment:
POSTGRES_USER: cpcwood-circleci
POSTGRES_PASSWORD: "test"
POSTGRES_DB: home_server_test
environment:
BUNDLE_JOBS: "3"
BUNDLE_RETRY: "3"
PGHOST: 127.0.0.1
PGUSER: cpcwood-circleci
PGPASSWORD: "test"
DB_NAME_TEST: home_server_test
RAILS_ENV: test
steps:
- checkout
- browser-tools/install-browser-tools
- ruby/install-deps:
include-branch-in-cache-key: false
- node/install-packages:
pkg-manager: yarn
include-branch-in-cache-key: false
- run:
name: 'Wait for DB'
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: 'Database setup'
command: bundle exec rails db:schema:load --trace
- ruby/rspec-test
- run:
name: 'Rubocop linter'
command: bundle exec rubocop -a
- run:
name: 'JavaScript testing'
command: yarn test
- run:
name: 'JavaScript linting'
command: yarn lint
- run:
name: 'Automerge PR'
command: |
if [ -z "$CIRCLE_PULL_REQUEST" ]; then
echo 'Not in pull request, skipping automerge'
exit 0
fi
if ./scripts/circle-ci/circle-ci-auto-merge ; then
echo 'Merge successful'
else
echo 'Merge failed'
exit 1
fi
build:
docker:
- image: docker
steps:
- checkout
- setup_remote_docker:
version: 20.10.6
- run:
name: 'Docker Login'
command: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin >/dev/null 2>&1
- run:
name: 'Pull previous images for cache'
command: |
docker pull "$DOCKER_USERNAME/home-server-base" || true
docker pull "$DOCKER_USERNAME/home-server-app" || true
docker pull "$DOCKER_USERNAME/home-server-worker-dependencies" || true
docker pull "$DOCKER_USERNAME/home-server-worker" || true
- run:
name: 'Build home-server-base image'
command: |
docker build \
--cache-from "$DOCKER_USERNAME/home-server-base" \
-t "$DOCKER_USERNAME/home-server-base:$(echo $CIRCLE_SHA1 | head -c8)" \
-t $DOCKER_USERNAME/home-server-base:latest \
--build-arg grecaptcha_site_key=$GRECAPTCHA_SITE_KEY \
--build-arg MAX_MIND_LICENSE=$MAX_MIND_LICENSE \
-f ./.docker/dockerfiles/base.Dockerfile \
.
- run:
name: 'Build home-server-app image'
command: |
docker build \
--cache-from "$DOCKER_USERNAME/home-server-app" \
-t "$DOCKER_USERNAME/home-server-app:$(echo $CIRCLE_SHA1 | head -c8)" \
-t $DOCKER_USERNAME/home-server-app:latest \
-f ./.docker/dockerfiles/Dockerfile \
.
- run:
name: 'Build home-server-worker-dependencies image'
command: |
docker build \
--cache-from "$DOCKER_USERNAME/home-server-worker-dependencies" \
-t "$DOCKER_USERNAME/home-server-worker-dependencies:$(echo $CIRCLE_SHA1 | head -c8)" \
-t $DOCKER_USERNAME/home-server-worker-dependencies:latest \
-f ./.docker/dockerfiles/worker-dependencies.Dockerfile \
.
- run:
name: 'Build home-server-worker image'
command: |
docker build \
--cache-from "$DOCKER_USERNAME/home-server-worker" \
-t "$DOCKER_USERNAME/home-server-worker:$(echo $CIRCLE_SHA1 | head -c8)" \
-t $DOCKER_USERNAME/home-server-worker:latest \
-f ./.docker/dockerfiles/worker.Dockerfile \
.
- run:
name: 'Publish images'
command: |
docker push --all-tags "$DOCKER_USERNAME/home-server-base"
docker push --all-tags "$DOCKER_USERNAME/home-server-app"
docker push --all-tags "$DOCKER_USERNAME/home-server-worker-dependencies"
docker push --all-tags "$DOCKER_USERNAME/home-server-worker"
deploy:
docker:
- image: cimg/base:stable
steps:
- checkout
- kubernetes/install-kubectl
- run:
name: 'Update config files in ./kube with current container version'
command: find ./.kube/ -type f | xargs sed -i "s/CONTAINER_VERSION/$(echo $CIRCLE_SHA1 | head -c8)/g"
- run:
name: 'Creating cluster certificate from ENV'
command: echo "$KUBERNETES_CLUSTER_CERTIFICATE" | base64 --decode > cert.crt
- run:
name: 'Apply Kubernetes config to server'
command: |
kubectl --kubeconfig=/dev/null \
--certificate-authority=cert.crt \
--server=$KUBERNETES_SERVER \
--token=$KUBERNETES_SERVICE_ACC_TOKEN \
apply -Rf ./.kube/app/
- run:
name: 'Remove cluster certificate artifact'
command: rm -f cert.crt
when: always