forked from shopsys/shopsys
-
Notifications
You must be signed in to change notification settings - Fork 0
243 lines (243 loc) · 14.1 KB
/
docker-build.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
on:
push:
branches:
- 'master'
- '[1-9].[0-9]'
tags:
- '**'
pull_request:
branches:
- '**'
name: "Docker build"
jobs:
cancel:
name: Cancel previous workflow runs
runs-on: ubuntu-20.04
steps:
- name: Cancelling
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
build-docker-images:
if: github.event.pull_request.head.repo.full_name == 'shopsys/shopsys'
name: Build PHP-FPM and Elasticsearch images
needs: cancel
runs-on: ubuntu-20.04
steps:
- name: GIT checkout branch - ${{ github.ref }}
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Check if PHP-FPM image exists
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
DOCKER_PHP_FPM_IMAGE_TAG=gitlab-action-`find project-base/docker/php-fpm -type f -exec stat -c "%a %n" {} \; -exec cat {} \; | md5sum | awk '{ print $1 }'`
echo "DOCKER_PHP_FPM_IMAGE_TAG=${DOCKER_PHP_FPM_IMAGE_TAG}" >> $GITHUB_ENV
echo "DOCKER_USERNAME=${DOCKER_USERNAME}" >> $GITHUB_ENV
DOCKER_PHP_FPM_IMAGE_EXISTS=`. .github/check-image-exists.sh && checkImageExists ${DOCKER_USERNAME} php-fpm ${DOCKER_PHP_FPM_IMAGE_TAG} > /dev/null ; echo $?`
echo "DOCKER_PHP_FPM_IMAGE_EXISTS=${DOCKER_PHP_FPM_IMAGE_EXISTS}" >> $GITHUB_ENV
- name: Build PHP-FPM image and push it to Docker Hub
if: env.DOCKER_PHP_FPM_IMAGE_EXISTS == 0
run: .github/build-php-fpm-image.sh
- name: Check if Elasticseach image exists
run: |
DOCKER_ELASTICSEARCH_IMAGE_TAG=gitlab-action-`find project-base/docker/elasticsearch -type f -exec stat -c "%a %n" {} \; -exec cat {} \; | md5sum | awk '{ print $1 }'`
echo "DOCKER_ELASTICSEARCH_IMAGE_TAG=${DOCKER_ELASTICSEARCH_IMAGE_TAG}" >> $GITHUB_ENV
DOCKER_ELASTICSEARCH_IMAGE_EXISTS=`. .github/check-image-exists.sh && checkImageExists ${DOCKER_USERNAME} elasticsearch ${DOCKER_ELASTICSEARCH_IMAGE_TAG} > /dev/null ; echo $?`
echo "DOCKER_ELASTICSEARCH_IMAGE_EXISTS=${DOCKER_ELASTICSEARCH_IMAGE_EXISTS}" >> $GITHUB_ENV
- name: Build Elasticsearch image and push it to Docker Hub
if: env.DOCKER_ELASTICSEARCH_IMAGE_EXISTS == 0
run: .github/build-elasticsearch-image.sh
- name: Copy and rename docker-compose.github-actions.yml.dist to docker-compose.yml
run: cp -f ./docker/conf/docker-compose.github-actions.yml.dist ./docker-compose.yml
- name: Update docker-compose.yml file with right PHP-FPM image
run: "sed -i \"s#php-fpm-image#${{ secrets.DOCKER_USERNAME }}/php-fpm:${DOCKER_PHP_FPM_IMAGE_TAG}-${{ github.sha }}#\" ./docker-compose.yml"
- name: Update docker-compose.yml file with right Elastichsearch image
run: "sed -i \"s#elasticsearch-image#${{ secrets.DOCKER_USERNAME }}/elasticsearch:${DOCKER_ELASTICSEARCH_IMAGE_TAG}#\" ./docker-compose.yml"
- name: Create branch specific PHP-FPM image with project files
run: |
docker run -d --name php-fpm ${{ secrets.DOCKER_USERNAME }}/php-fpm:${DOCKER_PHP_FPM_IMAGE_TAG}
docker cp ./ php-fpm:/var/www/html
docker exec php-fpm composer install --optimize-autoloader --no-interaction
docker exec php-fpm php phing dirs-create test-dirs-create assets npm build-version-generate backend-api-install composer-dev backend-api-oauth-keys-generate frontend-api-enable
- name: Push branch specific PHP-FPM image to Docker Hub
run: |
docker commit -m="Include Composer and NPM files" php-fpm ${{ secrets.DOCKER_USERNAME }}/php-fpm:${DOCKER_PHP_FPM_IMAGE_TAG}-${{ github.sha }}
docker image push ${{ secrets.DOCKER_USERNAME }}/php-fpm:${DOCKER_PHP_FPM_IMAGE_TAG}-${{ github.sha }}
- name: Upload docker-compose.yml to artifacts
uses: actions/upload-artifact@v2
with:
name: docker-compose
path: ./docker-compose.yml
standards:
name: Check standards
needs: build-docker-images
runs-on: ubuntu-20.04
steps:
- name: Download docker-compose.yml from artifacts
uses: actions/[email protected]
with:
name: docker-compose
- name: Build application
run: docker-compose up -d php-fpm
- name: Check standards
run: docker-compose exec -T php-fpm php phing standards
tests-unit-functional-smoke:
name: Run unit, functional and smoke tests
needs: build-docker-images
runs-on: ubuntu-20.04
steps:
- name: GIT checkout branch - ${{ github.ref }}
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Download docker-compose.yml from artifacts
uses: actions/[email protected]
with:
name: docker-compose
- name: Build application
run: |
docker-compose pull --parallel postgres elasticsearch redis php-fpm
docker-compose up -d postgres elasticsearch redis php-fpm
docker-compose exec -T php-fpm php phing db-create test-db-create db-demo elasticsearch-index-recreate elasticsearch-export error-pages-generate
- name: Run tests
run: docker-compose exec -T php-fpm php phing tests
- name: PHP-FPM container logs
if: ${{ failure() }}
run: docker-compose logs php-fpm
tests-acceptance:
name: Run acceptance tests
needs: build-docker-images
runs-on: ubuntu-20.04
steps:
- name: GIT checkout branch - ${{ github.ref }}
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Download docker-compose.yml from artifacts
uses: actions/[email protected]
with:
name: docker-compose
- name: Build application
run: |
docker-compose pull --parallel webserver postgres elasticsearch redis php-fpm selenium-server
docker-compose up -d
docker-compose exec -T php-fpm php phing dirs-create db-create test-db-create db-demo error-pages-generate test-db-demo test-elasticsearch-index-recreate test-elasticsearch-export tests-acceptance-build
- name: Run acceptance tests
run: docker-compose exec -T php-fpm php phing tests-acceptance
- name: PHP-FPM container logs
if: ${{ failure() }}
run: docker-compose logs php-fpm
- name: Copy Codeception logs from container
if: ${{ failure() }}
run: docker cp shopsys-framework-php-fpm:/var/www/html/project-base/var/log ./project-base/var/log
- name: Upload Codeception logs to artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: acceptance-logs
path: ./project-base/var/log/
build-fork-docker-images:
if: github.event.pull_request.head.repo.full_name != 'shopsys/shopsys'
name: Build application and run standards checks and tests
needs: cancel
runs-on: ubuntu-20.04
steps:
- name: GIT checkout branch - ${{ github.ref }}
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Check if PHP-FPM image exists
env:
DOCKER_USERNAME: shopsysbot
run: |
DOCKER_PHP_FPM_IMAGE_TAG=gitlab-action-`find project-base/docker/php-fpm -type f -exec stat -c "%a %n" {} \; -exec cat {} \; | md5sum | awk '{ print $1 }'`
echo "DOCKER_PHP_FPM_IMAGE_TAG=${DOCKER_PHP_FPM_IMAGE_TAG}" >> $GITHUB_ENV
echo "DOCKER_USERNAME=${DOCKER_USERNAME}" >> $GITHUB_ENV
DOCKER_PHP_FPM_IMAGE_EXISTS=`. .github/check-image-exists.sh && checkImageExists ${DOCKER_USERNAME} php-fpm ${DOCKER_PHP_FPM_IMAGE_TAG} > /dev/null ; echo $?`
echo ${DOCKER_PHP_FPM_IMAGE_EXISTS}
echo "DOCKER_PHP_FPM_IMAGE_EXISTS=${DOCKER_PHP_FPM_IMAGE_EXISTS}" >> $GITHUB_ENV
- name: Build PHP-FPM image
if: env.DOCKER_PHP_FPM_IMAGE_EXISTS == 0
run: |
docker image build \
--build-arg project_root=project-base \
--build-arg www_data_uid=$(id -u) \
--build-arg www_data_gid=$(id -g) \
--tag ${DOCKER_USERNAME}/php-fpm:${DOCKER_PHP_FPM_IMAGE_TAG} \
--target development \
--no-cache \
--compress \
-f project-base/docker/php-fpm/Dockerfile \
.
- name: Check if Elasticseach image exists
run: |
DOCKER_ELASTICSEARCH_IMAGE_TAG=gitlab-action-`find project-base/docker/elasticsearch -type f -exec stat -c "%a %n" {} \; -exec cat {} \; | md5sum | awk '{ print $1 }'`
echo "DOCKER_ELASTICSEARCH_IMAGE_TAG=${DOCKER_ELASTICSEARCH_IMAGE_TAG}" >> $GITHUB_ENV
DOCKER_ELASTICSEARCH_IMAGE_EXISTS=`. .github/check-image-exists.sh && checkImageExists ${DOCKER_USERNAME} elasticsearch ${DOCKER_ELASTICSEARCH_IMAGE_TAG} > /dev/null ; echo $?`
echo "DOCKER_ELASTICSEARCH_IMAGE_EXISTS=${DOCKER_ELASTICSEARCH_IMAGE_EXISTS}" >> $GITHUB_ENV
- name: Build Elasticsearch image
if: env.DOCKER_ELASTICSEARCH_IMAGE_EXISTS == 0
run: |
docker image build \
--tag ${DOCKER_USERNAME}/elasticsearch:${DOCKER_ELASTICSEARCH_IMAGE_TAG} \
--no-cache \
--compress \
-f project-base/docker/elasticsearch/Dockerfile \
.
- name: Copy and rename docker-compose.github-actions.yml.dist to docker-compose.yml
run: cp -f ./docker/conf/docker-compose.github-actions.yml.dist ./docker-compose.yml
- name: Update docker-compose.yml file with right PHP-FPM image
run: "sed -i \"s#php-fpm-image#${DOCKER_USERNAME}/php-fpm:${DOCKER_PHP_FPM_IMAGE_TAG}#\" ./docker-compose.yml"
- name: Update docker-compose.yml file with right Elastichsearch image
run: "sed -i \"s#elasticsearch-image#${DOCKER_USERNAME}/elasticsearch:${DOCKER_ELASTICSEARCH_IMAGE_TAG}#\" ./docker-compose.yml"
- name: Build application
run: |
docker-compose pull --parallel webserver postgres redis selenium-server
docker-compose up -d
docker cp ./ shopsys-framework-php-fpm:/var/www/html
docker-compose exec -T php-fpm composer install --optimize-autoloader --no-interaction
docker-compose exec -T php-fpm php phing dirs-create test-dirs-create assets npm build-version-generate backend-api-install composer-dev backend-api-oauth-keys-generate frontend-api-enable db-create test-db-create db-demo elasticsearch-index-recreate elasticsearch-export error-pages-generate test-db-demo test-elasticsearch-index-recreate test-elasticsearch-export tests-acceptance-build
- name: Check standards
run: docker-compose exec -T php-fpm php phing standards
- name: Run tests
run: docker-compose exec -T php-fpm php phing tests
- name: Run acceptance tests
run: docker-compose exec -T php-fpm php phing tests-acceptance
- name: PHP-FPM container logs
if: ${{ failure() }}
run: docker-compose logs php-fpm
- name: Copy Codeception logs from container
if: ${{ failure() }}
run: docker cp shopsys-framework-php-fpm:/var/www/html/project-base/var/log ./project-base/var/log
- name: Upload Codeception logs to artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: acceptance-logs
path: ./project-base/var/log/
build-successful:
if: ${{ always() }}
name: Build successful
needs: [tests-acceptance, standards, tests-unit-functional-smoke, build-fork-docker-images]
runs-on: ubuntu-20.04
env:
BUILD_FORK_RESULT: ${{ needs.build-fork-docker-images.result }}
STANDARDS_RESULT: ${{ needs.standards.result }}
TESTS_RESULT: ${{ needs.tests-unit-functional-smoke.result }}
TESTS_ACCEPTANCE_RESULT: ${{ needs.tests-acceptance.result }}
steps:
- name: GIT checkout branch - ${{ github.ref }}
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Build successful
run: |
EXIT_CODE=`. .github/get-build-exit-code.sh && getBuildExitCodeBasedOnJobResults ${BUILD_FORK_RESULT} ${STANDARDS_RESULT} ${TESTS_RESULT} ${TESTS_ACCEPTANCE_RESULT} > /dev/null ; echo $?`
exit "${EXIT_CODE}"