-
Notifications
You must be signed in to change notification settings - Fork 301
165 lines (151 loc) · 6.63 KB
/
testserver.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
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
161
162
163
164
165
name: Deploy to Testserver with Helios
on:
workflow_dispatch:
inputs:
HELIOS_TRIGGERED_BY:
description: "Username that triggered deployment"
required: true
type: string
HELIOS_BRANCH_NAME:
description: "Which branch to deploy"
required: true
type: string
HELIOS_BRANCH_HEAD_SHA:
description: "SHA of the branch to deploy"
required: true
type: string
HELIOS_ENVIRONMENT_NAME:
description: "Which environment to deploy (e.g. artemis-test7.artemis.cit.tum.de, etc.)."
required: true
type: string
HELIOS_RAW_URL:
description: "URL to the raw content of the repository in the format https://raw.githubusercontent.com/:owner/:repo/:sha"
required: true
type: string
HELIOS_BUILD:
description: "Whether to also build or just deploy the existing Docker image"
required: true
type: boolean
HELIOS_PR_NUMBER:
description: "PR number that triggered deployment"
required: false
type: string
HELIOS_BUILD_TAG:
description: "Docker tag to use if we are building or pulling an existing image"
required: false
type: string
concurrency: ${{ github.event.inputs.HELIOS_ENVIRONMENT_NAME }}
env:
CI: true
RAW_URL: ${{ github.event.inputs.HELIOS_RAW_URL }}
jobs:
# Print the inputs for debugging
validate-inputs:
runs-on: ubuntu-latest
steps:
- name: Validate Build Tag Input Exists
if: ${{ github.event.inputs.HELIOS_BUILD == 'true' && github.event.inputs.HELIOS_BUILD_TAG == '' }}
run: |
echo "::error::HELIOS_BUILD is true but no HELIOS_BUILD_TAG was provided."
exit 1
- name: Validate PR Number Input Exists
if: ${{ github.event.inputs.HELIOS_BUILD == 'false' && github.event.inputs.HELIOS_PR_NUMBER == '' }}
run: |
echo "::error::HELIOS_BUILD is false but no HELIOS_PR_NUMBER was provided."
exit 1
- name: Print Inputs
run: |
echo "RAW_URL: ${{ env.RAW_URL }}"
echo "Triggered by: ${{ github.event.inputs.HELIOS_TRIGGERED_BY }}"
echo "Branch: ${{ github.event.inputs.HELIOS_BRANCH_NAME }}"
echo "SHA: ${{ github.event.inputs.HELIOS_BRANCH_HEAD_SHA }}"
echo "PR Number: ${{ github.event.inputs.HELIOS_PR_NUMBER }}"
echo "Environment: ${{ github.event.inputs.HELIOS_ENVIRONMENT_NAME }}"
echo "Need Build? ${{ github.event.inputs.HELIOS_BUILD }}"
echo "Build Tag? ${{ github.event.inputs.HELIOS_BUILD_TAG }}"
# Build the Docker image (branch without PR)
conditional-build:
if: ${{ github.event.inputs.HELIOS_BUILD == 'true' }}
needs: [ validate-inputs ]
uses: ./.github/workflows/build.yml
with:
sha: ${{ github.event.inputs.HELIOS_BRANCH_HEAD_SHA }}
tag: ${{ github.event.inputs.HELIOS_BUILD_TAG }}
raw_url: ${{ github.event.inputs.HELIOS_RAW_URL }}
# Check if the build has run successfully (PR)
check-existing-build:
if: ${{ github.event.inputs.HELIOS_BUILD == 'false' }}
needs: [ validate-inputs ]
runs-on: ubuntu-latest
steps:
# Check if the build has run successfully (PR)
- name: Get latest successful build for branch
id: check_build
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/actions/workflows/build.yml/runs?event=pull_request&status=success&head_sha=${{ github.event.inputs.HELIOS_BRANCH_HEAD_SHA }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if no successful build found
if: ${{ steps.check_build.conclusion == 'success' && fromJSON(steps.check_build.outputs.data).total_count == 0 }}
run: |
echo "::error::No successful build found for branch '${{ github.event.inputs.HELIOS_BRANCH_NAME }}' with SHA '${{ github.event.inputs.HELIOS_BRANCH_HEAD_SHA }}'."
exit 1
# Deploy to the test servers
deploy:
needs: [ conditional-build, check-existing-build ]
# Run if either job is successful
# This if condition should be exactly like below, since one of the job is skipped
if: always() && (needs.conditional-build.result == 'success' || needs.check-existing-build.result == 'success')
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.HELIOS_ENVIRONMENT_NAME }}
url: ${{ vars.DEPLOYMENT_URL }}
env:
GATEWAY_USER: "jump"
GATEWAY_HOST: "gateway.artemis.in.tum.de:2010"
GATEWAY_HOST_PUBLIC_KEY: "[gateway.artemis.in.tum.de]:2010 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKtTLiKRILjKZ+Qg4ReWKsG7mLDXkzHfeY5nalSQUNQ4"
steps:
- name: Compute Tag
uses: actions/github-script@v7
id: compute-tag
with:
result-encoding: string
script: |
// Check if HELIOS_BUILD input is true
if (context.payload.inputs.HELIOS_BUILD === 'true') {
return context.payload.inputs.HELIOS_BUILD_TAG;
}
// Use the "pr-<pr-number>" format for pull requests
if (context.payload.inputs.HELIOS_BUILD === 'false') {
const prNumber = '${{ github.event.inputs.HELIOS_PR_NUMBER }}';
return `pr-${prNumber}`;
}
return "FALSE";
# Download artemis-server-cli from GH without cloning the Repo
- name: Fetch Artemis CLI
run: |
wget ${{ env.RAW_URL }}/artemis-server-cli
chmod +x artemis-server-cli
# Configure SSH Key
- name: Setup SSH Keys and known_hosts
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
GATEWAY_SSH_KEY: "${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}"
DEPLOYMENT_SSH_KEY: "${{ secrets.DEPLOYMENT_SSH_KEY }}"
run: |
mkdir -p ~/.ssh
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< $GATEWAY_SSH_KEY
ssh-add - <<< $DEPLOYMENT_SSH_KEY
cat - <<< $GATEWAY_HOST_PUBLIC_KEY >> ~/.ssh/known_hosts
- name: Deploy Artemis with Docker
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
TAG: ${{ steps.compute-tag.outputs.result }}
run: |
echo "DEPLOYMENT_HOSTS: ${{ vars.DEPLOYMENT_HOSTS }}"
echo "DEPLOYMENT_LABEL_IDENTIFIER: ${{ vars.DEPLOYMENT_LABEL_IDENTIFIER }}"
echo "DEPLOYMENT_URL: ${{ vars.DEPLOYMENT_URL }}"
echo "DEPLOYMENT_USER: ${{ vars.DEPLOYMENT_USER }}"
./artemis-server-cli docker-deploy "${{ vars.DEPLOYMENT_USER }}@${{ vars.DEPLOYMENT_HOSTS }}" -g "$GATEWAY_USER@$GATEWAY_HOST" -t $TAG -b ${{ github.event.inputs.HELIOS_BRANCH_NAME }} -d ${{ vars.DEPLOYMENT_FOLDER }} -y