-
Notifications
You must be signed in to change notification settings - Fork 9
131 lines (113 loc) · 3.85 KB
/
medicines-api-master.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
name: medicines-api-master
on:
push:
branches:
- master
paths:
- rust-toolchain
- medicines/api/**
- medicines/search-client/**
- manifests/medicines-api/**
- .github/workflows/medicines-api-master.yaml
- .github/workflows/medicines-api-release.yaml
env:
IMAGE: mhraproductsnonprodregistry.azurecr.io/products/medicines-api
jobs:
build-and-test:
name: Build, Test and Deploy
runs-on: ubuntu-latest
steps:
- name: Clone Repo
uses: actions/checkout@v2
with:
path: products
- uses: dorny/[email protected]
id: filter
with:
working-directory: products
filters: |
src:
- rust-toolchain
- medicines/api/**/*
- medicines/search-client/**/*
- name: Docker login
uses: azure/docker-login@v1
if: steps.filter.outputs.src == 'true'
with:
login-server: mhraproductsnonprodregistry.azurecr.io
username: mhraproductsnonprodregistry
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Make toolchain version available in current directory
if: steps.filter.outputs.src == 'true'
run: cp products/rust-toolchain .
- uses: actions-rs/toolchain@v1
if: steps.filter.outputs.src == 'true'
with:
components: clippy
- name: Cache cargo
uses: actions/cache@v2
if: steps.filter.outputs.src == 'true'
with:
path: |
~/.cargo/registry
~/.cargo/git
products/medicines/api/target
key: cargo-${{ hashFiles('products/medicines/api/Cargo.lock') }}-1
- name: Build and test Medicines API service
if: steps.filter.outputs.src == 'true'
working-directory: products/medicines/api
run: |
set -e
cargo clippy --release -- -D warnings
cargo build --release
cargo test --release
- name: Create Docker tag
working-directory: products/medicines/api
run: |
TAG="$(git rev-parse --short=7 ${{ github.sha }})"
echo "TAG=$TAG" >>$GITHUB_ENV
- name: Build and push Docker image
if: steps.filter.outputs.src == 'true'
working-directory: products/medicines/api
run: |
make ci-master tag=$TAG image=$IMAGE
DIGEST="$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE}:${TAG})"
echo "DIGEST=$DIGEST" >>$GITHUB_ENV
- name: Clone Deployments repo
uses: actions/checkout@v2
with:
repository: MHRA/deployments
path: deployments
token: ${{ secrets.DEPLOYMENTS_REPO_TOKEN }}
- name: Update image tag
uses: stefanprodan/kube-tools@v1
with:
kustomize: 3.4.0
command: |
set -eux
SOURCE="${PWD}/products/manifests/medicines-api/overlays/non-prod"
DEST="${PWD}/deployments/medicines-api/non-prod"
DEST_MANIFESTS="${DEST}/manifests.yaml"
cd $SOURCE
mkdir -p "${DEST}"
set +u
if [[ -n "${DIGEST}" ]]; then
kustomize edit set image $DIGEST
else
cat "${DEST_MANIFESTS}" | awk '/image:/ {print}' | sed 's/image://' | xargs kustomize edit set image
fi
set -u
kustomize build . > "${DEST_MANIFESTS}"
cd $DEST
git config --local user.email "[email protected]"
git config --local user.name "MHRA CI/CD"
git add --all
git diff-index --quiet HEAD || git commit -m "CI: Update image for $TAG"
declare -i n
n=0
until [ $n -ge 5 ]
do
git push && break
n+=1
git pull --rebase
done