-
Notifications
You must be signed in to change notification settings - Fork 87
128 lines (106 loc) · 3.94 KB
/
build_release_docker_image.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
name: Publish release Docker image
on:
release:
types:
- created
env:
IMAGE_NAME: metrik
jobs:
test-build-push-image:
name: 'Run tests, build artifacts and push image'
runs-on: ubuntu-latest
services:
mongo:
image: mongo:4.4-bionic
env:
TZ: "Asia/Shanghai"
ports:
- 27017:27017
steps:
- name: Setup timezone
run: sudo timedatectl set-timezone "Asia/Shanghai"
- uses: actions/checkout@v2
- name: Setup Java JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-package: 'jdk'
java-version: '11'
check-latest: true
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run backend tests
uses: ./.github/actions/backend_test
with:
working-dir: ./backend
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Cache Node.js packages
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Run frontend tests
uses: ./.github/actions/frontend_test
with:
working-dir: ./frontend
- name: Collect artifacts
run: |
ARTIFACT_DIR="./ci/artifacts"
mkdir -p $ARTIFACT_DIR/backend
mkdir $ARTIFACT_DIR/frontend
cp -rp ./frontend/dist $ARTIFACT_DIR/frontend/
cp -p ./backend/build/libs/metrik-backend-*.jar $ARTIFACT_DIR/backend/
cp -p ./backend/run.sh $ARTIFACT_DIR/backend/
- name: Install AWS CLI
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --update
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to AWS ECR
run: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_PUBLIC_ECR_ACCOUNT_URL }}
- name: Build and push Docker image
run: |
IMAGE_ID=${{ secrets.AWS_PUBLIC_ECR_ACCOUNT_URL }}/${{ secrets.AWS_PUBLIC_ECR_REPO }}
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
docker build . --file Dockerfile --tag $IMAGE_ID:latest --tag $IMAGE_ID:$VERSION --label "runnumber=${GITHUB_RUN_ID}" --label "hash=${GITHUB_SHA}"
IFS="," read -ra DOCKER_TAGS <<< "latest,$VERSION"
for tag in "${DOCKER_TAGS[@]}"; do
docker push $IMAGE_ID:$tag
done
working-directory: ./ci
# - name: Build and push Docker image
# run: |
# IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
#
# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
#
# # Strip "v" prefix from tag name
# VERSION=$(echo ${{ github.event.release.tag_name }} | sed -e 's/^v//')
#
# docker build . --file Dockerfile --tag $IMAGE_ID:latest --tag $IMAGE_ID:$VERSION --label "runnumber=${GITHUB_RUN_ID}" --label "hash=${GITHUB_SHA}"
#
# IFS="," read -ra DOCKER_TAGS <<< "latest,$VERSION"
# for tag in "${DOCKER_TAGS[@]}"; do
# docker push $IMAGE_ID:$tag
# done
# working-directory: ./ci