Skip to content

Commit 01d19ef

Browse files
committed
feat: initial commit
Signed-off-by: Gabor Boros <gabor@opencraft.com>
0 parents  commit 01d19ef

File tree

86 files changed

+14386
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+14386
-0
lines changed

.editorconfig

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# All files
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
# Shell scripts
14+
[*.{sh,bash}]
15+
indent_style = space
16+
indent_size = 4
17+
max_line_length = 120
18+
19+
# Markdown files
20+
[*.md]
21+
indent_style = space
22+
indent_size = 2
23+
max_line_length = 80
24+
trim_trailing_whitespace = false
25+
26+
# YAML files
27+
[*.{yml,yaml}]
28+
indent_style = space
29+
indent_size = 2
30+
max_line_length = 120
31+
32+
# JSON files
33+
[*.json]
34+
indent_style = space
35+
indent_size = 2
36+
max_line_length = 120
37+
38+
# Python files
39+
[*.py]
40+
indent_style = space
41+
indent_size = 4
42+
max_line_length = 88
43+
44+
# Go files
45+
[*.go]
46+
indent_style = tab
47+
indent_size = 4
48+
max_line_length = 120
49+
50+
# Terraform files
51+
[*.{tf,tfvars}]
52+
indent_style = space
53+
indent_size = 2
54+
max_line_length = 120

.github/workflows/build.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: Build Service Image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
INSTANCE_NAME:
7+
description: "Instance to build"
8+
required: true
9+
type: string
10+
SERVICE:
11+
description: "Service to build"
12+
required: true
13+
type: string
14+
STRAIN_REPOSITORY:
15+
description: "Repository containing the cluster/strains"
16+
required: true
17+
type: string
18+
STRAIN_REPOSITORY_BRANCH:
19+
description: "Branch to clone the strain from"
20+
required: true
21+
type: string
22+
TUTOR_VERSION:
23+
description: "Version of the tutor to use"
24+
required: true
25+
type: string
26+
PICASSO_VERSION:
27+
description: "Picasso version"
28+
required: true
29+
type: string
30+
PHD_CLI_VERSION:
31+
description: "PHD CLI version"
32+
required: true
33+
type: string
34+
RUNNER_WORKFLOW_LABEL:
35+
description: "The label of the runner workflow to run"
36+
required: false
37+
type: string
38+
default: "ubuntu-latest"
39+
secrets:
40+
SSH_PRIVATE_KEY:
41+
description: "Private SSH key for accessing private repositories"
42+
required: true
43+
44+
concurrency:
45+
group: ${{ inputs.STRAIN_REPOSITORY }}:${{ inputs.STRAIN_REPOSITORY_BRANCH }}:${{ inputs.INSTANCE_NAME }}:${{ inputs.SERVICE }}
46+
cancel-in-progress: true
47+
48+
jobs:
49+
build:
50+
name: Build with Picasso
51+
uses: open-craft/picasso/.github/workflows/build.yml@gabor/add-ghcr-support
52+
permissions:
53+
packages: write
54+
contents: read
55+
secrets:
56+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
57+
with:
58+
STRAIN_REPOSITORY: ${{ inputs.STRAIN_REPOSITORY }}
59+
STRAIN_REPOSITORY_BRANCH: ${{ inputs.STRAIN_REPOSITORY_BRANCH }}
60+
STRAIN_PATH: "instances/${{ inputs.INSTANCE_NAME }}"
61+
SERVICE: ${{ inputs.SERVICE }}
62+
IMAGE_TAG_PREFIX: ${{ inputs.SERVICE }}
63+
USE_DYNAMIC_IMAGE_TAG: true
64+
ADD_RANDOM_SUFFIX_TO_IMAGE_TAG: true
65+
RANDOM_SUFFIX_LENGTH: "8"
66+
TIMESTAMP_FORMAT: "%Y%m%d"
67+
PICASSO_VERSION: ${{ inputs.PICASSO_VERSION }}
68+
PYTHON_VERSION: 3.12
69+
# Prevent updating the image tag in the config.yml -- it would cause two
70+
# commits as we commit other config changes later. We want to avoid confusion
71+
# and have a single commit for the whole config update.
72+
UPDATE_IMAGE_TAG_IN_REPO: false
73+
RUNNER_WORKFLOW_LABEL: ${{ inputs.RUNNER_WORKFLOW_LABEL }}
74+
75+
generate-env-dir:
76+
needs:
77+
- build
78+
name: Generate Environment Directory
79+
uses: open-craft/phd-cluster-template/.github/workflows/generate-env-dir.yml@main
80+
secrets:
81+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
82+
with:
83+
INSTANCE_NAME: ${{ inputs.INSTANCE_NAME }}
84+
SERVICE: ${{ inputs.SERVICE }}
85+
IMAGE_TAG: ${{ needs.build.outputs.image_tag }}
86+
STRAIN_REPOSITORY: ${{ inputs.STRAIN_REPOSITORY }}
87+
STRAIN_REPOSITORY_BRANCH: ${{ inputs.STRAIN_REPOSITORY_BRANCH }}
88+
TUTOR_VERSION: ${{ inputs.TUTOR_VERSION }}
89+
PICASSO_VERSION: ${{ inputs.PICASSO_VERSION }}
90+
PHD_CLI_VERSION: ${{ inputs.PHD_CLI_VERSION }}
91+
RUNNER_WORKFLOW_LABEL: ${{ inputs.RUNNER_WORKFLOW_LABEL }}
92+
93+
commit-and-push:
94+
needs:
95+
- build
96+
- generate-env-dir
97+
runs-on: ${{ inputs.RUNNER_WORKFLOW_LABEL }}
98+
concurrency:
99+
group: ${{ inputs.STRAIN_REPOSITORY }}:${{ inputs.STRAIN_REPOSITORY_BRANCH }}:${{ inputs.INSTANCE_NAME }}:commit
100+
cancel-in-progress: false
101+
steps:
102+
- name: Setup SSH agent
103+
uses: webfactory/ssh-agent@v0.9.0
104+
with:
105+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
106+
107+
- name: Add GitHub to known hosts
108+
run: ssh-keyscan github.com >> ~/.ssh/known_hosts
109+
110+
- name: Checkout cluster repository
111+
uses: actions/checkout@v4
112+
with:
113+
repository: ${{ inputs.STRAIN_REPOSITORY }}
114+
ref: ${{ inputs.STRAIN_REPOSITORY_BRANCH }}
115+
fetch-depth: 0
116+
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
117+
118+
- name: Configure git
119+
run: |
120+
git config user.name "GitHub Actions"
121+
git config user.email "actions@github.com"
122+
123+
- name: Checkout Picasso for scripts
124+
uses: actions/checkout@v4
125+
with:
126+
repository: open-craft/picasso
127+
ref: ${{ inputs.PICASSO_VERSION }}
128+
path: picasso
129+
130+
- name: Setup Python
131+
uses: actions/setup-python@v5
132+
with:
133+
python-version: 3.12
134+
cache: 'pip'
135+
cache-dependency-path: picasso/requirements/base.txt
136+
137+
- name: Install requirements
138+
run: pip install -r picasso/requirements/base.txt
139+
140+
- name: Download env artifact
141+
uses: actions/download-artifact@v4
142+
with:
143+
name: tutor-env-${{ inputs.INSTANCE_NAME }}
144+
path: instances/${{ inputs.INSTANCE_NAME }}/env
145+
146+
147+
148+
- name: Update config.yml with image tag
149+
env:
150+
CONFIG_FILE: instances/${{ inputs.INSTANCE_NAME }}/config.yml
151+
SCRIPT_PATH: picasso/.github/workflows/scripts/dynamic_image_tag.py
152+
SERVICE: ${{ inputs.SERVICE }}
153+
IMAGE_TAG: ${{ needs.build.outputs.image_tag }}
154+
run: |
155+
python $SCRIPT_PATH \
156+
--config-file "$CONFIG_FILE" \
157+
--service "$SERVICE" \
158+
--save-config "true" \
159+
--image-tag "$IMAGE_TAG"
160+
161+
- name: Commit and push changes
162+
env:
163+
INSTANCE_NAME: ${{ inputs.INSTANCE_NAME }}
164+
SERVICE: ${{ inputs.SERVICE }}
165+
IMAGE_TAG: ${{ needs.build.outputs.image_tag }}
166+
BRANCH: ${{ inputs.STRAIN_REPOSITORY_BRANCH }}
167+
SCRIPT_PATH: picasso/.github/workflows/scripts/dynamic_image_tag.py
168+
CONFIG_FILE: instances/${{ inputs.INSTANCE_NAME }}/config.yml
169+
run: |
170+
set -euo pipefail
171+
172+
git add instances/$INSTANCE_NAME/config.yml
173+
git add instances/$INSTANCE_NAME/env
174+
175+
if git diff --cached --quiet; then
176+
echo "No changes to commit"
177+
exit 0
178+
fi
179+
180+
git commit -m "chore: update $SERVICE image and tutor config for $INSTANCE_NAME"
181+
182+
for i in 1 2 3; do
183+
if git push; then
184+
exit 0
185+
fi
186+
sleep $((i*i))
187+
git pull origin "$BRANCH" --rebase
188+
# Re-apply the config update on top of latest base in case of rebase changes
189+
python "$SCRIPT_PATH" \
190+
--config-file "$CONFIG_FILE" \
191+
--service "$SERVICE" \
192+
--save-config "true" \
193+
--image-tag "$IMAGE_TAG"
194+
git add instances/$INSTANCE_NAME/config.yml
195+
git add instances/$INSTANCE_NAME/env
196+
if git diff --cached --quiet; then
197+
echo "No additional changes after rebase"
198+
else
199+
git commit -m "chore: update $SERVICE image and tutor config for $INSTANCE_NAME (retry $i)" || true
200+
fi
201+
done
202+
exit 1

0 commit comments

Comments
 (0)