Skip to content

Commit 0172c56

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

File tree

87 files changed

+14493
-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.

87 files changed

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

0 commit comments

Comments
 (0)