-
Notifications
You must be signed in to change notification settings - Fork 1
160 lines (133 loc) · 4.72 KB
/
ci.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: CI
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: buoy-barn-buildx-${{ github.sha }}
restore-keys: |
buoy-barn-buildx-
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/myimage.tar
key: buoy-barn-image-${{ github.sha }}
restore-keys: |
buoy-barn-image-
- name: Login to Docker Hub
uses: docker/[email protected]
continue-on-error: true
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Buoy Barn
uses: docker/[email protected]
with:
context: ./app
push: false
tags: gmri/neracoos-buoy-barn:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
outputs: type=docker,dest=/tmp/myimage.tar
- name: Move Docker Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
test:
name: Unit Tests
runs-on: ubuntu-24.04
timeout-minutes: 15
needs: build
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/myimage.tar
key: buoy-barn-image-${{ github.sha }}
restore-keys: |
buoy-barn-image-
- name: Load Docker image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
- name: Test
run: make test
- name: Send coverage to Codacy (skip coverage if no project token secret)
run: |
pip install --user codacy-coverage
~/.local/bin/python-codacy-coverage -r app/coverage.xml
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
if: env.CODACY_PROJECT_TOKEN != null
deploy:
name: Build and Push tagged image to Docker Hub, and update Argo config
runs-on: ubuntu-24.04
needs: test
environment:
name: Buoy Barn via Argo CD
url: https://buoy-barn.neracoos.org/admin/
if: |
github.repository == 'gulfofmaine/buoy_barn'
&& contains(github.ref, 'refs/tags/v')
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/myimage.tar
key: buoy-barn-image-${{ github.sha }}
restore-keys: |
buoy-barn-image-
- name: Load Docker image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
- name: "Login to Docker Hub"
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get tag name
uses: olegtarasov/[email protected]
id: tagName
- name: Tag Docker image
run: docker tag gmri/neracoos-buoy-barn gmri/neracoos-buoy-barn:${{ steps.tagName.outputs.tag }}
- name: Push Docker image
run: docker push gmri/neracoos-buoy-barn:${{ steps.tagName.outputs.tag }}
- name: Make GitOps directory
run: mkdir gitops
- name: Clone GitOps config repo
run: git clone "https://[email protected]/gulfofmaine/neracoos-aws-cd.git"
working-directory: ./gitops
env:
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
- name: Update GitOps config repo
working-directory: ./gitops/neracoos-aws-cd
run: |
sed -i 's/?ref=.\+/?ref=${{ steps.tagName.outputs.tag }}/' overlays/buoy-barn/kustomization.yaml
sed -i 's/newTag: .\+/newTag: ${{ steps.tagName.outputs.tag }}/' overlays/buoy-barn/kustomization.yaml
git config --global user.email '[email protected]'
git config --global user.name 'NERACOOS Buoy Barn CI'
git diff --exit-code && echo 'Already Deployed' || (git commit -am 'Upgrade Buoy Barn to ${{ steps.tagName.outputs.tag }}' && git push)
- name: Create Sentry Release
uses: getsentry/[email protected]
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: prod
version: ${{ steps.tagName.outputs.tag }}