Skip to content

Commit a760713

Browse files
committed
Theia Cloud Preview Deployments
* Build Theia IDE Preview Image * Disable Licence check on fork * Push to Artifact Registry * Create Cluster Infrastructure * Deploy App Definition * Cleanup App Definition * install missing dependencies on ubuntu system * allow multiple sessions per user
1 parent 24b32f3 commit a760713

File tree

12 files changed

+1015
-3
lines changed

12 files changed

+1015
-3
lines changed

.github/workflows/license-check-workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ on:
55
branches:
66
- master
77
workflow_dispatch:
8-
pull_request:
9-
branches:
10-
- master
8+
# pull_request:
9+
# branches:
10+
# - master
1111
schedule:
1212
- cron: '0 4 * * *' # Runs every day at 4am: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule
1313

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Cleanup Theia IDE Preview Deployment
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: The image's tag
12+
required: true
13+
default: next
14+
theia_version:
15+
description: Theia Version
16+
required: false
17+
default: next
18+
19+
pull_request:
20+
branches: [master]
21+
types:
22+
- closed
23+
24+
jobs:
25+
build:
26+
name: Cleanup Theia IDE Preview image
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
33+
- name: Set the Theia version
34+
id: set-theia-version
35+
run: |
36+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
37+
echo "THEIA_VERSION=${{ github.event.inputs.theia_version }}" >> $GITHUB_ENV
38+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
39+
echo "THEIA_VERSION=" >> $GITHUB_ENV
40+
else
41+
echo "THEIA_VERSION=next" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Set image tag
45+
id: set-tag
46+
run: |
47+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
48+
echo "IMAGE_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
49+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
50+
echo "IMAGE_TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
51+
elif [ "${{ github.event_name }}" == "schedule" ]; then
52+
echo "IMAGE_TAG=weekly" >> $GITHUB_ENV
53+
else
54+
echo "IMAGE_TAG=other" >> $GITHUB_ENV
55+
fi
56+
57+
- name: Authenticate to Google Cloud
58+
uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
59+
with:
60+
credentials_json: ${{ secrets.GCP_SA_KEY }}
61+
project_id: kubernetes-238012
62+
create_credentials_file: true
63+
64+
- name: Setup Google Cloud SDK
65+
uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a # v2.1.4
66+
67+
- name: Get GKE Credentials
68+
uses: google-github-actions/get-gke-credentials@d0cee45012069b163a631894b98904a9e6723729 # v2.3.3
69+
with:
70+
cluster_name: github-theia-ide-preview
71+
location: europe-west3-c
72+
73+
- name: List sessions in theia-cloud namespace
74+
run: kubectl get sessions -n theia-cloud
75+
76+
- name: List apps in theia-cloud namespace
77+
run: kubectl get appdefinitions -n theia-cloud
78+
79+
- name: Delete app definition if existent
80+
run: kubectl delete appdefinitions theia-ide-${{ env.IMAGE_TAG }} -n theia-cloud || true
81+
82+
- name: Delete existing sessions
83+
run: kubectl get sessions -n theia-cloud -o json | jq -r '.items[] | select(.spec.appDefinition == "theia-ide-${{ env.IMAGE_TAG }}") | .metadata.name' | xargs -r kubectl delete sessions -n theia-cloud
84+
85+
- name: Update bot comment
86+
if: github.event_name == 'pull_request'
87+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #7.0.1
88+
with:
89+
script: |
90+
const {data: comments} = await github.rest.issues.listComments({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: context.payload.number,
94+
})
95+
const botComment = comments.find(comment => comment.user.id === 41898282)
96+
const commentBody = "No Preview Deployment"
97+
if (botComment) {
98+
await github.rest.issues.updateComment({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
comment_id: botComment.id,
102+
body: commentBody
103+
})
104+
} else {
105+
await github.rest.issues.createComment({
106+
owner: context.repo.owner,
107+
repo: context.repo.repo,
108+
issue_number: context.payload.number,
109+
body: commentBody
110+
})
111+
}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: Publish Theia IDE Preview Deployment
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: The image's tag
12+
required: true
13+
default: next
14+
theia_version:
15+
description: Theia Version
16+
required: false
17+
default: next
18+
19+
pull_request:
20+
branches: [master]
21+
types:
22+
- opened
23+
- synchronize
24+
- reopened
25+
26+
schedule:
27+
- cron: '0 13 * * 0'
28+
29+
concurrency:
30+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
31+
cancel-in-progress: true
32+
33+
jobs:
34+
build:
35+
name: Build Theia IDE Preview image
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v2
41+
42+
- name: Use Node.js 20.x
43+
uses: actions/setup-node@v3
44+
with:
45+
node-version: 20.x
46+
registry-url: 'https://registry.npmjs.org'
47+
48+
- name: Use Python 3.11
49+
uses: actions/setup-python@v4
50+
with:
51+
python-version: '3.11'
52+
53+
- name: Install dependencies for native-keymap
54+
run: sudo apt-get update && sudo apt-get install -y libx11-dev libxkbfile-dev
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
58+
59+
- name: Set the Theia version
60+
id: set-theia-version
61+
run: |
62+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
63+
echo "THEIA_VERSION=${{ github.event.inputs.theia_version }}" >> $GITHUB_ENV
64+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
65+
echo "THEIA_VERSION=" >> $GITHUB_ENV
66+
else
67+
echo "THEIA_VERSION=next" >> $GITHUB_ENV
68+
fi
69+
70+
- name: Run Theia update if version is specified
71+
if: ${{ env.THEIA_VERSION != '' }}
72+
run: |
73+
yarn && yarn update:theia ${THEIA_VERSION} && yarn update:theia:children ${THEIA_VERSION} && yarn
74+
75+
- name: Set image tag
76+
id: set-tag
77+
run: |
78+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
79+
echo "IMAGE_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
80+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
81+
echo "IMAGE_TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
82+
elif [ "${{ github.event_name }}" == "schedule" ]; then
83+
echo "IMAGE_TAG=weekly" >> $GITHUB_ENV
84+
else
85+
echo "IMAGE_TAG=other" >> $GITHUB_ENV
86+
fi
87+
88+
- name: Authenticate to Google Cloud
89+
uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
90+
with:
91+
credentials_json: ${{ secrets.GCP_SA_KEY }}
92+
project_id: kubernetes-238012
93+
create_credentials_file: true
94+
95+
- name: Setup Google Cloud SDK
96+
uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a # v2.1.4
97+
98+
- name: Configure Docker for Artifact Registry
99+
run: |
100+
gcloud auth configure-docker europe-west3-docker.pkg.dev
101+
102+
- name: Update bot comment
103+
if: github.event_name == 'pull_request'
104+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #7.0.1
105+
with:
106+
script: |
107+
const {data: comments} = await github.rest.issues.listComments({
108+
owner: context.repo.owner,
109+
repo: context.repo.repo,
110+
issue_number: context.payload.number,
111+
})
112+
const botComment = comments.find(comment => comment.user.id === 41898282)
113+
const commentBody = "Thank you for opening the PR!\n\nThis comment will be replaced with a link to a Preview deployment as soon as it is ready."
114+
if (botComment) {
115+
await github.rest.issues.updateComment({
116+
owner: context.repo.owner,
117+
repo: context.repo.repo,
118+
comment_id: botComment.id,
119+
body: commentBody
120+
})
121+
} else {
122+
await github.rest.issues.createComment({
123+
owner: context.repo.owner,
124+
repo: context.repo.repo,
125+
issue_number: context.payload.number,
126+
body: commentBody
127+
})
128+
}
129+
130+
- name: Build Docker image
131+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
132+
with:
133+
context: .
134+
file: browser.Dockerfile
135+
push: true
136+
tags: |
137+
europe-west3-docker.pkg.dev/kubernetes-238012/theia-ide-preview/theia-ide-preview:${{ env.IMAGE_TAG }}
138+
139+
- name: Get GKE Credentials
140+
uses: google-github-actions/get-gke-credentials@d0cee45012069b163a631894b98904a9e6723729 # v2.3.3
141+
with:
142+
cluster_name: github-theia-ide-preview
143+
location: europe-west3-c
144+
145+
- name: List sessions in theia-cloud namespace
146+
run: kubectl get sessions -n theia-cloud
147+
148+
- name: List apps in theia-cloud namespace
149+
run: kubectl get appdefinitions -n theia-cloud
150+
151+
- name: Delete app definition if existent
152+
run: kubectl delete appdefinitions theia-ide-${{ env.IMAGE_TAG }} -n theia-cloud || true
153+
154+
- name: Delete existing sessions
155+
run: kubectl get sessions -n theia-cloud -o json | jq -r '.items[] | select(.spec.appDefinition == "theia-ide-${{ env.IMAGE_TAG }}") | .metadata.name' | xargs -r kubectl delete sessions -n theia-cloud
156+
157+
- name: Create app definition
158+
run: |
159+
cat <<EOF | kubectl apply -f -
160+
apiVersion: theia.cloud/v1beta10
161+
kind: AppDefinition
162+
metadata:
163+
name: theia-ide-${{ env.IMAGE_TAG }}
164+
namespace: theia-cloud
165+
spec:
166+
downlinkLimit: 30000
167+
image: europe-west3-docker.pkg.dev/kubernetes-238012/theia-ide-preview/theia-ide-preview:${{ env.IMAGE_TAG }}
168+
imagePullPolicy: Always
169+
ingressname: theia-cloud-demo-ws-ingress
170+
limitsCpu: "2"
171+
limitsMemory: 500M
172+
maxInstances: 3
173+
minInstances: 0
174+
mountPath: /home/project/persisted
175+
name: theia-ide-${{ env.IMAGE_TAG }}
176+
port: 3000
177+
requestsCpu: "100m"
178+
requestsMemory: 300M
179+
timeout: 15
180+
uid: 101
181+
uplinkLimit: 30000
182+
EOF
183+
184+
- name: Update bot comment with URL
185+
if: github.event_name == 'pull_request'
186+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #7.0.1
187+
with:
188+
script: |
189+
const {data: comments} = await github.rest.issues.listComments({
190+
owner: context.repo.owner,
191+
repo: context.repo.repo,
192+
issue_number: context.payload.number,
193+
})
194+
const botComment = comments.find(comment => comment.user.id === 41898282)
195+
const commentBody = "Preview deployment created at https://launch.theia-ide-preview.eclipsesource-munich.com/?appDef=theia-ide-${{ env.IMAGE_TAG }}\n\nWhen the deployment is cleaned up, this link will be removed again."
196+
if (botComment) {
197+
await github.rest.issues.updateComment({
198+
owner: context.repo.owner,
199+
repo: context.repo.repo,
200+
comment_id: botComment.id,
201+
body: commentBody
202+
})
203+
} else {
204+
await github.rest.issues.createComment({
205+
owner: context.repo.owner,
206+
repo: context.repo.repo,
207+
issue_number: context.payload.number,
208+
body: commentBody
209+
})
210+
}

.terraform/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.terraform
2+
terraform.tfstate
3+
terraform.tfstate.backup

0 commit comments

Comments
 (0)