-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (120 loc) · 4.74 KB
/
docker.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
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# For multi-platform builds
# https://github.com/docker/build-push-action/blob/master/docs/advanced/multi-platform.md
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Initialize
id: init
run: |
# Determine whether to push to Docker Hub based on the event type
case "${{ github.event_name }}" in
push)
DOCKER_PUSH=true ;;
*)
DOCKER_PUSH=false ;;
esac
# Map git ref branch or tag name to Docker tag version
case "${{ github.ref }}" in
# Do not push upstream branches and tags to Docker Hub
refs/heads/upstream/*|refs/tags/upstream/*)
DOCKER_PUSH=false ;;
# Do not push pull request branches
refs/pulls/*)
DOCKER_PUSH=false ;;
esac
echo ::set-output name=docker_push::$DOCKER_PUSH
echo ::set-output name=docker_repo::whoi/$(basename "${{ github.repository }}" | tr A-Z a-z)
echo ::set-output name=docker_platforms::linux/amd64,linux/arm64
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ steps.init.outputs.docker_repo }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
- name: Log into registry
if: steps.init.outputs.docker_push == 'true'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Enable Docker layer caching in the GitHub Actions cache.
#
# https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-multi-buildx
- name: Build the Docker image for native
uses: docker/build-push-action@v2
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# These are still used by the /version API
build-args: |
GIT_SOURCE=${{ steps.init.outputs.git_source }}
GIT_REVISION=${{ steps.init.outputs.git_revision }}
cache-from: |
type=local,src=/tmp/.buildx-cache
type=registry,ref=${{ steps.init.outputs.docker_repo }}:buildcache
cache-to: |
type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Tag latest for CI testing
run: |
docker tag \
${{ fromJSON(steps.meta.outputs.json).tags[0] }} \
${{ steps.init.outputs.docker_repo }}
- name: Run test suite
run: docker compose run sealog-server npm run start-test
- name: Run server and Postman tests
run: |
docker compose up -d
sleep 10
curl http://localhost:8000/sealog-server > /tmp/banner.txt
grep "Welcome to sealog-server\!" /tmp/banner.txt
# Install Newman for running Postman tests
npm install -g newman
# Run Postman tests
newman run "integration-tests/api_tests.postman_collection.json"
docker compose down
# Because `docker buildx build` cannot have multiple cache export targets
# yet, we build and push separately.
#
# During the build step (above), we update the GitHub Actions cache. Then
# we use this cache to rebuild, pushing both the image and the cache up to
# the registry.
- name: Push
if: steps.init.outputs.docker_push == 'true'
uses: docker/build-push-action@v2
with:
context: .
platforms: ${{ steps.init.outputs.docker_platforms }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# These are still used by the /version API
build-args: |
GIT_SOURCE=${{ steps.init.outputs.git_source }}
GIT_REVISION=${{ steps.init.outputs.git_revision }}
cache-from: |
type=local,src=/tmp/.buildx-cache-new
cache-to: |
type=registry,ref=${{ steps.init.outputs.docker_repo }}:buildcache,mode=max
- name: Update cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache