Skip to content

Commit c728752

Browse files
feat: build images in cluster with kaniko (#9)
* feat(skaffold): update config to build with kaniko * feat: add just recipes to build with kaniko * chore: placeholder docker-config.json example * chore: update gitignore * chore: add gcp_project_id to envrc example * chore: add test containerfile * chore: update deployment image * fix: scipod now built by kaniko in cluster
1 parent 0b6237a commit c728752

File tree

10 files changed

+128
-32
lines changed

10 files changed

+128
-32
lines changed

.envrc.example

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export CONTAINER_BUILDER=podman # path to container management executable
2+
export GCP_PROJECT_ID=project-111111 # gcp project id
23
export GITHUB_USERNAME=username # github username associated to uploading startup scripts as github gists
34
export GITHUB_ORG_NAME=sciexp # name of the github org or user containing the github repository with code for development
45
export GITHUB_REPO_NAME=scidev # name of a github repository with a conda environment yaml file

.github/workflows/ci.yaml

-17
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,3 @@ jobs:
4646
containerfile-path: "containers/Containerfile.${{ github.job }}"
4747
push-condition: ${{ github.event_name != 'pull_request' }}
4848
github-token: ${{ secrets.GITHUB_TOKEN }}
49-
50-
scipod:
51-
needs: [scan,scidev]
52-
runs-on: ubuntu-latest
53-
permissions:
54-
contents: read
55-
packages: write
56-
steps:
57-
- uses: actions/checkout@v4
58-
- name: Tag Build and Push Testing Container
59-
uses: ./.github/actions/tag-build-push-container
60-
with:
61-
registry: ghcr.io
62-
image-name: ${{ github.repository_owner }}/${{ github.job }}
63-
containerfile-path: "containers/Containerfile.${{ github.job }}"
64-
push-condition: ${{ github.event_name != 'pull_request' }}
65-
github-token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.direnv
22
.envrc
3+
kaniko-key.json
4+
docker-config.json

cluster/resources/deployment.cue

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ deployment: scidev: {
2121
metadata: labels: app: "scidev"
2222
spec: {
2323
containers: [{
24-
name: "dev"
25-
image: "ghcr.io/sciexp/scidev"
24+
name: "scidev"
25+
image: "ghcr.io/sciexp/scipod"
2626
imagePullPolicy: "IfNotPresent"
27-
command: ["/bin/sh", "-c", "sleep infinity"]
27+
command: [
28+
"/bin/sh",
29+
"-c",
30+
"sleep infinity",
31+
]
2832
resources: {
2933
requests: {
3034
cpu: "16"
@@ -41,15 +45,13 @@ deployment: scidev: {
4145
mountPath: "/workspace"
4246
}]
4347
}]
44-
4548
nodeSelector: {
4649
"gpu-type": "nvidia-tesla-t4"
47-
"spot": "true"
50+
spot: "false"
4851
}
49-
5052
volumes: [{
5153
name: "scidev"
52-
persistentVolumeClaim: claimName: "scidev-claim"
54+
persistentVolumeClaim: claimName: "scidev"
5355
}]
5456
}
5557
}

cluster/resources/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
spec:
2121
containers:
2222
- name: scidev
23-
image: ghcr.io/sciexp/scidev
23+
image: ghcr.io/sciexp/scipod
2424
imagePullPolicy: IfNotPresent
2525
command:
2626
- /bin/sh

containers/Containerfile.test

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM debian:stable-slim
2+
3+
ENTRYPOINT [ "/bin/sh" ]

docker-config.example.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"auths": {
3+
"ghcr.io": {
4+
"auth": "`echo "username:ghp_TOKEN" | base64`"
5+
}
6+
}
7+
}

justfile

+25
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ builder := env_var_or_default('BUILDER', 'podman')
2323
container_user := "runner"
2424
container_home := "/home" / container_user
2525
container_work := container_home / "work"
26+
gcp_project_id := env_var_or_default('GCP_PROJECT_ID', 'sciexp')
2627
git_username := env_var_or_default('GITHUB_USERNAME', 'sciexp')
2728
git_org_name := env_var_or_default('GITHUB_ORG_NAME', 'sciexp')
2829
git_repo_name := env_var_or_default('GITHUB_REPO_NAME', 'scidev')
@@ -134,6 +135,10 @@ info:
134135
render:
135136
skaffold render -t latest
136137

138+
# Build image with skaffold
139+
build:
140+
skaffold build
141+
137142
# Deploy latest container_image in current kube context (invert: terminate)
138143
deploy:
139144
skaffold deploy -t latest
@@ -154,6 +159,26 @@ terminate:
154159
delete:
155160
skaffold delete
156161

162+
kaniko_service_account_email := "kaniko-" + git_repo_name + "@" + gcp_project_id + ".iam.gserviceaccount.com"
163+
164+
# Create kaniko service account and download key
165+
get-kaniko-credentials:
166+
gcloud iam service-accounts describe {{kaniko_service_account_email}} || \
167+
gcloud iam service-accounts create kaniko-{{git_repo_name}} --display-name="kaniko {{git_repo_name}} service account" && \
168+
gcloud projects add-iam-policy-binding {{gcp_project_id}} \
169+
--member=serviceAccount:{{kaniko_service_account_email}} \
170+
--role=roles/artifactregistry.createOnPushWriter \
171+
--role=roles/artifactregistry.repositories.uploadArtifacts
172+
gcloud iam service-accounts keys create ./kaniko-key.json \
173+
--iam-account {{kaniko_service_account_email}}
174+
175+
# Create container regcred from docker-config.json to use with pullSecretName: regcred if private
176+
create-regcred:
177+
kubectl create secret generic regcred \
178+
--from-file=.dockerconfigjson=./docker-config.json \
179+
--type=kubernetes.io/dockerconfigjson \
180+
--dry-run=client -o yaml > ./regcred-secret.yaml
181+
157182
#---------------------
158183
# container management
159184
#---------------------

skaffold.cue

+45-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,51 @@ config: {
99
"cluster/resources/deployment.yaml",
1010
]
1111
deploy: kubectl: defaultNamespace: "scidev"
12-
build: artifacts: [{
13-
image: "ghcr.io/sciexp/scidev"
14-
docker: dockerfile: "containers/Containerfile.scidev"
15-
}]
12+
build: {
13+
artifacts: [{
14+
// - image: ghcr.io/sciexp/scidev
15+
// docker:
16+
// dockerfile: containers/Containerfile.scidev
17+
// - image: us-central1-docker.pkg.dev/sciexp/scidev/scipod
18+
// docker:
19+
// dockerfile: containers/Containerfile.scipod
20+
image: "ghcr.io/sciexp/scipod"
21+
kaniko: {
22+
dockerfile: "containers/Containerfile.scipod"
23+
cache: {
24+
ttl: "168h"
25+
cacheCopyLayers: true
26+
}
27+
}
28+
}]
29+
tagPolicy: sha256: {}
30+
31+
cluster: {
32+
namespace: "scidev"
33+
// With GCP credentials
34+
// pullSecretPath: ./kaniko-key.json
35+
// pullSecretName: kaniko-secret
36+
// if private, with docker-style credentials
37+
// pullSecretName: regcred
38+
// randomPullSecret: true
39+
// docker-style push credentials
40+
dockerConfig: {
41+
path: "./docker-config.json"
42+
}
43+
resources: {
44+
requests: {
45+
cpu: "8"
46+
memory: "16Gi"
47+
}
48+
limits: {
49+
cpu: "32"
50+
memory: "180Gi"
51+
}
52+
}
53+
concurrency: 5
54+
}
55+
}
56+
1657
profiles: [{
1758
name: "dev"
1859
deploy: statusCheckDeadlineSeconds: 960

skaffold.yaml

+35-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,41 @@ deploy:
1010
defaultNamespace: scidev
1111
build:
1212
artifacts:
13-
- image: ghcr.io/sciexp/scidev
14-
docker:
15-
dockerfile: containers/Containerfile.scidev
13+
# - image: ghcr.io/sciexp/scidev
14+
# docker:
15+
# dockerfile: containers/Containerfile.scidev
16+
# - image: us-central1-docker.pkg.dev/sciexp/scidev/scipod
17+
# docker:
18+
# dockerfile: containers/Containerfile.scipod
19+
- image: ghcr.io/sciexp/scipod
20+
kaniko:
21+
dockerfile: containers/Containerfile.scipod
22+
cache:
23+
ttl: 168h
24+
cacheCopyLayers: true
25+
tagPolicy:
26+
sha256: {}
27+
28+
cluster:
29+
namespace: scidev
30+
# With GCP credentials
31+
# pullSecretPath: ./kaniko-key.json
32+
# pullSecretName: kaniko-secret
33+
# if private, with docker-style credentials
34+
# pullSecretName: regcred
35+
# randomPullSecret: true
36+
# docker-style push credentials
37+
dockerConfig:
38+
path: ./docker-config.json
39+
resources:
40+
requests:
41+
cpu: "8"
42+
memory: 16Gi
43+
limits:
44+
cpu: "32"
45+
memory: 180Gi
46+
concurrency: 5
47+
1648
profiles:
1749
- name: dev
1850
deploy:

0 commit comments

Comments
 (0)