forked from ChainSafe/ChainBridge
-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (137 loc) · 4.32 KB
/
docker-build-and-push.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
# Copyright 2020 ChainSafe Systems
# SPDX-License-Identifier: LGPL-3.0-only
name: Docker build and push
on:
push:
branches:
# when main branch receives a push
- main
# when any of these versions receive a push
tags:
- "v*.*.*"
# when any releases are created
release:
types:
- created
# list jobs
jobs:
build-and-deploy:
name: Docker Deployment
runs-on: ubuntu-latest
# requires these jobs to run first
needs: [test, e2e, lint]
# if check not passed, job will be skipped
if: github.ref == 'refs/heads/main' || contains(github.ref, '/tags/v')
# list steps
steps:
# prepares docker images
- name: Prepare
id: prep
run: |
# creates local variable of chainbridge docker image
DOCKER_IMAGE=chainsafe/chainbridge
# creates local variable of commit hash that triggered workflow
COMMIT_HASH=$(echo $GITHUB_SHA | head -c7)
# creates local variable to hold docker images
TAGS="${DOCKER_IMAGE}:${COMMIT_HASH},${DOCKER_IMAGE}:latest"
# check if branch/tag that triggered workflow was from tags
if [[ $GITHUB_REF == refs/tags/* ]]; then
# set version
VERSION=${GITHUB_REF#refs/tags/}
# append version to tags
TAGS="${TAGS},${DOCKER_IMAGE}:${VERSION}"
fi
# sets output of step
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
test:
name: Tests
strategy:
matrix:
go-version: [1.15.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Subkey
run: |
wget -P $HOME/.local/bin/ https://chainbridge.ams3.digitaloceanspaces.com/subkey-v2.0.0
mv $HOME/.local/bin/subkey-v2.0.0 $HOME/.local/bin/subkey
chmod +x $HOME/.local/bin/subkey
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Test
run: |
docker-compose -f ./docker-compose-e2e.yml up -d
sleep 3
docker ps
make test
e2e:
name: E2E Tests
strategy:
matrix:
go-version: [ 1.15.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Subkey
run: |
wget -P $HOME/.local/bin/ https://chainbridge.ams3.digitaloceanspaces.com/subkey-v2.0.0
mv $HOME/.local/bin/subkey-v2.0.0 $HOME/.local/bin/subkey
chmod +x $HOME/.local/bin/subkey
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Test
run: |
docker-compose -f ./docker-compose-e2e.yml up -d
docker ps
make test-e2e
lint:
name: Lint and License Headers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.36
args: --timeout=5m
- name: License Check
run: make license-check