Skip to content

Commit e9951e4

Browse files
authored
Merge pull request #1 from gitpod-io/aledbf/expand-usage
Build custom image
2 parents 4562464 + a99977e commit e9951e4

File tree

9 files changed

+118
-28
lines changed

9 files changed

+118
-28
lines changed

.gitpod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
image:
2+
file: Dockerfile

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.1.0
3+
rev: v4.0.0
44
hooks:
55
- id: check-merge-conflict
66
- id: debug-statements

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
FROM eu.gcr.io/gitpod-core-dev/dev/dev-environment:base
3+
4+
# leeway
5+
ARG LEEWAY_VERSION=0.7.6
6+
ENV LEEWAY_MAX_PROVENANCE_BUNDLE_SIZE=8388608
7+
ENV LEEWAY_CACHE_DIR=/var/tmp/cache
8+
ENV LEEWAY_BUILD_DIR=/var/tmp/build
9+
10+
RUN cd /usr/bin && curl -fsSL https://github.com/gitpod-io/leeway/releases/download/v${LEEWAY_VERSION}/leeway_${LEEWAY_VERSION}_Linux_x86_64.tar.gz | sudo tar xz
11+
12+
RUN cd /usr/bin && curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.23.1/yq_linux_amd64 | sudo tee -a yq >/dev/null 2>&1 \
13+
&& sudo chmod +x yq
14+
15+
### Google Cloud ###
16+
# not installed via repository as then 'docker-credential-gcr' is not available
17+
ARG GCS_DIR=/opt/google-cloud-sdk
18+
ENV PATH=$GCS_DIR/bin:$PATH
19+
RUN sudo chown gitpod: /opt \
20+
&& mkdir $GCS_DIR \
21+
&& curl -fsSL https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-420.0.0-linux-x86_64.tar.gz \
22+
| tar -xzvC /opt \
23+
&& /opt/google-cloud-sdk/install.sh --quiet --usage-reporting=false --bash-completion=true \
24+
--additional-components gke-gcloud-auth-plugin docker-credential-gcr alpha beta \
25+
# needed for access to our private registries
26+
&& docker-credential-gcr configure-docker
27+
28+
RUN sudo install-packages python3-pip
29+
30+
RUN sudo python3 -m pip uninstall crcmod \
31+
&& sudo python3 -m pip install --no-cache-dir -U crcmod
32+
33+
# Install pre-commit https://pre-commit.com/#install
34+
RUN sudo install-packages shellcheck \
35+
&& sudo python3 -m pip install pre-commit
36+
37+
RUN wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg \
38+
&& echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list \
39+
&& sudo install-packages packer

action.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ image=
3232
image_family=
3333
scopes=
3434
shutdown_timeout=
35-
preemptible=
36-
ephemeral=
3735

3836
OPTLIND=1
3937
while getopts_long :h opt \
@@ -51,8 +49,6 @@ while getopts_long :h opt \
5149
image_family optional_argument \
5250
scopes required_argument \
5351
shutdown_timeout required_argument \
54-
preemptible required_argument \
55-
ephemeral required_argument \
5652
help no_argument "" "$@"; do
5753
case "$opt" in
5854
command)
@@ -97,12 +93,6 @@ while getopts_long :h opt \
9793
shutdown_timeout)
9894
shutdown_timeout=$OPTLARG
9995
;;
100-
preemptible)
101-
preemptible=$OPTLARG
102-
;;
103-
ephemeral)
104-
ephemeral=$OPTLARG
105-
;;
10696
h | help)
10797
usage
10898
exit 0
@@ -129,8 +119,6 @@ function start_vm {
129119
image_family_flag=$([[ -z "${image_family}" ]] || echo "--image-family=${image_family}")
130120
disk_size_flag=$([[ -z "${disk_size}" ]] || echo "--boot-disk-size=${disk_size}")
131121
boot_disk_type_flag=$([[ -z "${boot_disk_type}" ]] || echo "--boot-disk-type=${boot_disk_type}")
132-
preemptible_flag=$([[ "${preemptible}" == "true" ]] && echo "--preemptible" || echo "")
133-
ephemeral_flag=$([[ "${ephemeral}" == "true" ]] && echo "--ephemeral" || echo "")
134122
project_id_flag=$(echo "--project=${project_id}")
135123

136124
echo "The new GCE VM will be ${VM_ID}"
@@ -216,7 +204,6 @@ FILE_EOF
216204
${image_project_flag} \
217205
${image_flag} \
218206
${image_family_flag} \
219-
${preemptible_flag} \
220207
--maintenance-policy="TERMINATE" \
221208
--metadata-from-file="startup-script=/tmp/startup-script.sh,shutdown-script=/tmp/shutdown-script.sh" &&
222209
echo "label=${VM_ID}" >>"${GITHUB_OUTPUT}"

action.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inputs:
1818
machine_zone:
1919
description: GCE zone
2020
default: "europe-west1-b"
21-
required: true
21+
required: false
2222
machine_type:
2323
description: GCE machine type; https://cloud.google.com/compute/docs/machine-types
2424
default: "n2d-standard-8"
@@ -38,18 +38,10 @@ inputs:
3838
image:
3939
description: Specifies the name of the image that the disk will be initialized with.
4040
required: false
41-
default: gh-runner-202307162143
41+
default: gh-runner-202307241508
4242
image_family:
4343
description: The image family for the operating system that the boot disk will be initialized with.
4444
required: false
45-
preemptible:
46-
description: Use GCE preemptible VM instance; https://cloud.google.com/compute/docs/instances/preemptible
47-
default: false
48-
required: true
49-
ephemeral:
50-
description: Set GitHub runner to be ephemeral; https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling
51-
default: false
52-
required: true
5345
scopes:
5446
description: Scopes granted to the VM, defaults to full access (cloud-platform).
5547
default: cloud-platform
@@ -92,5 +84,3 @@ runs:
9284
--image=${{ inputs.image }}
9385
--image_family=${{ inputs.image_family }}
9486
--boot_disk_type=pd-ssd
95-
--preemptible=${{ inputs.preemptible }}
96-
--ephemeral=${{ inputs.ephemeral }}

create-vm.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Create ephemeral GCE VM
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
GCP_CREDENTIALS:
7+
required: true
8+
GH_SELF_HOSTED_RUNNER:
9+
required: true
10+
outputs:
11+
label:
12+
value: ${{ jobs.run.outputs.label }}
13+
14+
jobs:
15+
run:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
label: ${{ steps.create-runner.outputs.label }}
19+
steps:
20+
- uses: actions/checkout@v3
21+
- id: auth
22+
name: Authenticate to Google Cloud
23+
uses: google-github-actions/auth@v1
24+
with:
25+
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
26+
- id: gcloud-auth
27+
name: gcloud auth activate-service-account
28+
shell: bash
29+
run: |
30+
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
31+
- id: create-runner
32+
uses: gitpod-io/gce-github-runner@main
33+
with:
34+
token: ${{ secrets.GH_SELF_HOSTED_RUNNER }}

delete-vm.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Delete ephemeral GCE VM
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
runner-label:
7+
type: string
8+
required: true
9+
10+
secrets:
11+
GCP_CREDENTIALS:
12+
required: true
13+
14+
jobs:
15+
run:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- id: auth
20+
name: Authenticate to Google Cloud
21+
uses: google-github-actions/auth@v1
22+
with:
23+
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
24+
- id: gcloud-auth
25+
name: gcloud auth activate-service-account
26+
shell: bash
27+
run: |
28+
if [ -z "${{ inputs.runner-label }}" ];then
29+
exit 0
30+
fi
31+
32+
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
33+
if [ -z "$(gcloud compute instances list | grep "${{ inputs.runner-label }}")" ]; then
34+
# vm is gone
35+
exit 0
36+
fi
37+
38+
gcloud compute instances delete ${{ inputs.runner-label }} --quiet --zone ${{ inputs.runner-az }}

vm/rootfs/setup-runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
# go
6-
GO_VERSION=1.20.5
6+
GO_VERSION=1.20.6
77
GOPATH=/home/runner/go-packages
88
GOROOT=/home/runner/go
99
PATH=$GOROOT/bin:$GOPATH/bin:$PATH

vm/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export DEBIAN_FRONTEND=noninteractive
66

77
RUNNER_USER="runner"
88
RUNNER_DIR="/home/${RUNNER_USER}"
9-
RUNNER_VER=2.306.0
9+
RUNNER_VER=2.307.0
1010

1111
HELM_VERSION=3.12.1
1212

0 commit comments

Comments
 (0)