generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 6
134 lines (107 loc) · 5.54 KB
/
scheduled.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
name: Refresh EKS FINOS Legend deployment
on:
workflow_dispatch:
schedule:
# Runs everyday at 00:00. (see https://crontab.guru)
- cron: "0 0 * * *"
jobs:
build:
name: Trigger Juju refresh on EKS Deployment
runs-on: ubuntu-latest
steps:
- name: Installing Dependencies
run: |
sudo snap install juju --channel=3.6/stable --classic
- name: Install Docker
uses: docker-practice/actions-setup-docker@master
# We need the kubeconfig and the controllers.yaml file into our environment
# in order to login and refresh the charms.
- name: Adding Credentials
shell: bash
run: |
mkdir -p ~/.kube
mkdir -p ~/.local/share/juju
echo "${KUBECONFIG_B64}" | base64 -d > ~/.kube/config
echo "${CONTROLLERS_B64}" | base64 -d > ~/.local/share/juju/controllers.yaml
echo "${CONTROLLER_PASSWORD}" | juju login -c finos-legend-v36 -u admin
env:
KUBECONFIG_B64: "${{ secrets.KUBECONFIG_B64 }}"
CONTROLLERS_B64: "${{ secrets.CONTROLLERS_B64 }}"
CONTROLLER_PASSWORD: "${{ secrets.CONTROLLER_PASSWORD }}"
- name: Refreshing Charms
run: |
set -x
# We only refresh the staging environment. We need to check which model
# is the staging one. We can find it by the configured external-hostname.
# Controller name is "finos-legend-v36", model name is "finos-legend"
model="finos-legend-v36:finos-legend"
if [ "$(juju config -m $model legend-studio external-hostname)" != "staging.legend.finos.org" ]; then
model="finos-legend-v36:finos-legend-twin"
fi
juju switch "${model}"
# Running juju status will show us the current revisions of the charms.
juju status --relations
update-images() {
charm_name=$1
resource_name=$2
application_name=$3
juju resources ${application_name}/0 --details
download_url=$(curl -sL https://api.charmhub.io/v2/charms/resources/$charm_name/$resource_name/revisions | jq 'map( .[-1].download.url)'[0] | tr -d '"')
curl -sLo ${resource_name}_download.oci $download_url
ls
sha256sum ${resource_name}_download.oci
juju attach-resource --debug $application_name $resource_name=${resource_name}_download.oci
juju resources ${application_name}/0 --details
# charmhub_timestamp=$(curl -sL https://api.charmhub.io/v2/charms/resources/$charm_name/$resource_name/revisions | jq 'map( .[-1]."created-at")'[0] | tr -d '"')
# local_timestamp=$(juju resources $application_name --format=json | jq 'map( .[0].timestamp)'[0] | tr -d '"')
# charmhub_timestamp_ut=$(date -d ${charmhub_timestamp} +%s)
# local_timestamp_ut=$(date -d ${local_timestamp} +%s)
# if [ $charmhub_timestamp_ut -ge $local_timestamp_ut ];
# then
# download_url=$(curl -sL https://api.charmhub.io/v2/charms/resources/$charm_name/$resource_name/revisions | jq 'map( .[-1].download.url)'[0] | tr -d '"')
# curl -sLo $resource_name_download $download_url
# juju attach-resource $application_name $resource_name=$resource_name_download --debug
# else
# echo "Already running the latest image."
# fi
}
update-images finos-legend-engine-k8s engine-image legend-engine
update-images finos-legend-sdlc-k8s sdlc-image legend-sdlc
update-images finos-legend-studio-k8s studio-image legend-studio
# Updates the charm code if available
juju refresh legend-engine --channel="latest/edge"
juju refresh legend-sdlc --channel="latest/edge"
juju refresh legend-studio --channel="latest/edge"
# Running juju status will show us the current revisions of the charms.
juju status --relations
- name: Check Legend Public Instance status
run: |
wait_for_curl() {
url="$1"
expected_code="${2:-302 Found}"
for i in {1..40}; do
# Any request to any Legend Application should be redirected to gitlab.com
curl -i "${url}" | grep "${expected_code}" && break
if [ "$i" -eq 40 ]; then
echo "Failed to get '302 Found' response status from ${url}"
exit 1
fi
sleep 10
done
}
wait_for_curl "https://staging.legend.finos.org/engine/"
wait_for_curl "https://staging.legend.finos.org/api"
wait_for_curl "https://staging.legend.finos.org/studio"
wait_for_curl "https://staging.legend.finos.org/" "200 OK"
echo "Staging Legend is reachable, getting redirected to gitlab."
- name: Send email on failure
if: failure() && github.event_name == 'schedule'
uses: vineetchoudhary/mailgun-action@master
with:
api-key: ${{ secrets.MAILGUN_API_KEY }}
domain: ${{ secrets.MAILGUN_DOMAIN }}
to: ${{ secrets.EMAIL_TO }}
subject: "${{ github.job }} job of ${{ github.repository }} has failed"
body: "${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Send Mail Action Response
run: echo "${{ steps.sendmail.outputs.response }}"