-
Notifications
You must be signed in to change notification settings - Fork 8
124 lines (114 loc) · 3.78 KB
/
node_api.yml
File metadata and controls
124 lines (114 loc) · 3.78 KB
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
name: Build Node API
on: [pull_request, push]
env:
NODE_ENV: test
DB_TEST_HOST: localhost
DB_TEST_USERNAME: postgres
DB_TEST_PASSWORD: postgres
DB_TEST_DATABASE: sequence_test
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
JWT_AUDIENCE: ${{ secrets.JWT_AUDIENCE }}
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [15.x]
# Sequential jobs
max-parallel: 1
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sequence_test
ports:
- "5432:5432"
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: npm i -g --force yarn
- run: cd packages/common
- name: Install Common packages
working-directory: ./packages/common
run: yarn install
- name: Install API packages
working-directory: ./packages/api
run: yarn install
- name: Build API
working-directory: ./packages/api
run: yarn build
- name: Run API Tests
working-directory: ./packages/api
run: yarn migrate && yarn test
env:
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
JWT_AUDIENCE: ${{ secrets.JWT_AUDIENCE }}
push-image:
needs: build-and-test
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- name: Prepare
id: prep
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="sequenceso/sequence-api"
echo ::set-output name=tagged_image::${IMAGE}:${TAG}
echo ::set-output name=tag::${TAG}
./build/copy_env
- name: Set up docker buildx
uses: docker/setup-buildx-action@master
with:
install: true
- name: Cache docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build production image
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: ./Dockerfile.api
push: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
# Note the mode=max here
# More: https://github.com/moby/buildkit#--export-cache-options
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new