This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (114 loc) · 4 KB
/
deploy.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
name: Build and deploy
on:
push:
branches:
- main
env:
IMAGE: docker.pkg.github.com/${{ github.repository }}/podlet-template:${{ github.sha }}
LATEST_IMAGE: docker.pkg.github.com/${{ github.repository }}/podlet-template:latest
BASE_PATH: /arbeid/podlet-template
IMAGE_CACHE_RUNTIME: docker.pkg.github.com/${{ github.repository }}/podlet-template-build-cache-runtime
IMAGE_CACHE_BUILDER: docker.pkg.github.com/${{ github.repository }}/podlet-template-build-cache-builder
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up node
uses: actions/setup-node@v1
with:
node-version: '14.x'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Test
run: |
npm install --no-save --no-audit
npm test
build:
name: Build and Publish Docker image
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: docker.pkg.github.com
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
env:
DOCKER_BUILDKIT: 1
run: |
docker pull ${{ env.IMAGE_CACHE_BUILDER }} || true
docker pull ${{ env.IMAGE_CACHE_RUNTIME }} || true
docker build . -t ${{ env.IMAGE }} -t ${{ env.LATEST_IMAGE }} \
--cache-from=${{ env.IMAGE_CACHE_BUILDER }},${{ env.IMAGE_CACHE_RUNTIME }} \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg BASE_PATH=${{ env.BASE_PATH }} \
--build-arg VERSION_HASH=${{ github.sha }}
docker push ${{ env.IMAGE }}
docker push ${{ env.LATEST_IMAGE }}
- name: Archive NAIS yaml
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v1
with:
name: nais-yaml
path: nais
update-docker-cache:
name: Update Docker Cache
needs: [ build ]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: docker.pkg.github.com
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
env:
DOCKER_BUILDKIT: 1
run: |
docker pull ${{ env.IMAGE_CACHE_BUILDER }} || true
docker build . -t ${{ env.IMAGE_CACHE_BUILDER }} --target builder --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from=${{ env.IMAGE_CACHE_BUILDER }}
docker push ${{ env.IMAGE_CACHE_BUILDER }}
docker pull ${{ env.IMAGE_CACHE_RUNTIME }} || true
docker build . -t ${{ env.IMAGE_CACHE_RUNTIME }} --target runtime --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from=${{ env.IMAGE_CACHE_RUNTIME }}
docker push ${{ env.IMAGE_CACHE_RUNTIME }}
# deploy-dev:
# name: Deploy to dev
# needs: [ test, build ]
# if: github.ref == 'refs/heads/main'
# runs-on: ubuntu-latest
# steps:
# - name: Fetch NAIS yaml
# uses: actions/download-artifact@v1
# with:
# name: nais-yaml
# path: nais
#
# - uses: nais/deploy/actions/deploy@v1
# env:
# APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
# CLUSTER: dev-gcp
# RESOURCE: nais/nais.yaml
# VARS: nais/dev/vars.yaml
# PRINT_PAYLOAD: true