Skip to content

Commit cbf1399

Browse files
authored
Add full auto recreate github runners with tofu (#401)
1 parent 8d0729e commit cbf1399

8 files changed

Lines changed: 365 additions & 75 deletions

File tree

.github/workflows/tofu-apply.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ jobs:
2424
- uses: actions/checkout@v4
2525
with:
2626
fetch-depth: 2
27-
- uses: actions/setup-node@v4
28-
with:
29-
node-version: 20
30-
- uses: opentofu/setup-opentofu@v1
31-
with:
32-
tofu_version: 1.8.2
33-
- uses: nightstory/setup-yc@v1
3427
- run: |
3528
../scripts/tofu.sh --tofurc --cleanup --init --silent --apply --approve
3629
working-directory: ./terraform

.github/workflows/tofu-lint.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ jobs:
1818
- datalens-opensource
1919
steps:
2020
- uses: actions/checkout@v4
21-
- uses: actions/setup-node@v4
22-
with:
23-
node-version: 20
24-
- uses: opentofu/setup-opentofu@v1
25-
with:
26-
tofu_version: 1.8.2
2721
- run: |
2822
../scripts/tofu.sh --lint
2923
working-directory: ./terraform

.github/workflows/tofu-plan.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ jobs:
2424
- datalens-opensource
2525
steps:
2626
- uses: actions/checkout@v4
27-
- uses: actions/setup-node@v4
28-
with:
29-
node-version: 20
30-
- uses: opentofu/setup-opentofu@v1
31-
with:
32-
tofu_version: 1.8.2
3327
- run: |
3428
../scripts/tofu.sh --tofurc --cleanup --init --silent --plan --plan-out "../plan.tfplan" --plan-md
3529
working-directory: ./terraform

scripts/tofu.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,7 @@ if [ "${IS_LOCK}" == "true" ]; then
310310
-platform=linux_amd64 \
311311
-platform=linux_arm64 \
312312
-platform=darwin_arm64 \
313-
-platform=darwin_amd64 \
314-
hashicorp/dns \
315-
hashicorp/helm \
316-
hashicorp/http \
317-
hashicorp/local \
318-
hashicorp/random \
319-
hashicorp/time \
320-
hashicorp/tls \
321-
hashicorp/kubernetes \
322-
registry.terraform.io/yandex-cloud/yandex
313+
-platform=darwin_amd64
323314
fi
324315

325316
echo ""

terraform/.terraform.lock.hcl

Lines changed: 42 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#cloud-config
22
runcmd:
3-
- apt update && apt install -y jq zip unzip curl wget git docker.io docker-compose-v2
3+
- apt update && apt install -y jq zip unzip curl wget git devscripts docker.io docker-compose-v2 docker-buildx
44
# install github cli
55
- mkdir -p -m 755 /etc/apt/keyrings
66
- wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
@@ -12,40 +12,53 @@ runcmd:
1212
- apt install -y nodejs python3 python-is-python3 g++ make
1313
# install task cli
1414
- su - root -c "curl -o ./task-install.sh -L https://taskfile.dev/install.sh"
15-
- su - root -c "chmod +x ./task-install.sh && ./task-install.sh -d -b /usr/local/bin"
15+
- su - root -c "chmod +x ./task-install.sh && ./task-install.sh -b /usr/local/bin -d 'v${TASK_VERSION}'"
1616
# install aws cli
17-
- su - root -c "curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscli.zip"
17+
- su - root -c "curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWSCLI_VERSION}.zip -o awscli.zip"
1818
- su - root -c "unzip awscli.zip && ./aws/install --update && rm -rf awscli.zip && rm -rf ./aws"
1919
# install yc cli
2020
- su - root -c "curl -o ./yc-install.sh -L https://storage.yandexcloud.net/yandexcloud-yc/install.sh"
21-
- su - root -c "chmod +x ./yc-install.sh && ./yc-install.sh -i /tmp/yc -n && rm -rf ./yc-install.sh && mv /tmp/yc/bin/yc /usr/bin/yc"
21+
- su - root -c "chmod +x ./yc-install.sh && CLI_VERSION='${YC_VERSION}' ./yc-install.sh -i /tmp/yc -n && rm -rf ./yc-install.sh && mv /tmp/yc/bin/yc /usr/bin/yc"
2222
# install mc cli
2323
- su - root -c "curl https://dl.min.io/client/mc/release/linux-amd64/mc --create-dirs -o /usr/bin/mc"
2424
- su - root -c "chmod +x /usr/bin/mc"
2525
# install opentofu cli
26-
- su - root -c "curl -O -L https://github.com/opentofu/opentofu/releases/download/v1.8.4/tofu_1.8.4_linux_amd64.zip"
27-
- su - root -c "unzip tofu_1.8.4_linux_amd64.zip tofu -d /usr/bin/ && rm -f tofu_1.8.4_linux_amd64.zip && chmod +x /usr/bin/tofu"
26+
- su - root -c "curl -O -L https://github.com/opentofu/opentofu/releases/download/v${OPENTOFU_VERSION}/tofu_${OPENTOFU_VERSION}_linux_amd64.zip"
27+
- su - root -c "unzip tofu_${OPENTOFU_VERSION}_linux_amd64.zip tofu -d /usr/bin/ && rm -f tofu_${OPENTOFU_VERSION}_linux_amd64.zip && chmod +x /usr/bin/tofu"
2828
# install kubectl cli
29-
- su - root -c "curl -L https://dl.k8s.io/release/v1.31.5/bin/linux/amd64/kubectl -o /usr/bin/kubectl"
29+
- su - root -c "curl -L https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/bin/kubectl"
3030
- su - root -c "chmod +x /usr/bin/kubectl"
3131
# install helm cli
32-
- su - root -c "curl -O -L https://get.helm.sh/helm-v3.17.1-linux-amd64.tar.gz"
33-
- su - root -c "tar -xvzf helm-v3.17.1-linux-amd64.tar.gz && rm -rf helm-v3.17.1-linux-amd64.tar.gz && mv linux-amd64/helm /usr/bin/helm && rm -rf linux-amd64 && chmod +x /usr/bin/helm"
32+
- su - root -c "curl -O -L https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz"
33+
- su - root -c "tar -xvzf helm-v${HELM_VERSION}-linux-amd64.tar.gz && rm -rf helm-v${HELM_VERSION}-linux-amd64.tar.gz && mv linux-amd64/helm /usr/bin/helm && rm -rf linux-amd64 && chmod +x /usr/bin/helm"
3434
# install yq cli
35-
- su - root -c "curl -O -L https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_amd64.tar.gz"
35+
- su - root -c "curl -O -L https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64.tar.gz"
3636
- su - root -c "tar -xvzf yq_linux_amd64.tar.gz && rm -rf yq_linux_amd64.tar.gz && mv yq_linux_amd64 /usr/bin/yq && chmod +x /usr/bin/yq"
37+
# install trivy cli
38+
- su - root -c "curl -o ./trivy.tar.gz -L https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
39+
- su - root -c "tar -xvzf trivy.tar.gz && rm -rf trivy.tar.gz && mv trivy /usr/bin/trivy && chmod +x /usr/bin/trivy"
40+
# install shellformat cli
41+
- su - root -c "curl -L https://github.com/mvdan/sh/releases/download/v${SHFMT_VERSION}/shfmt_v${SHFMT_VERSION}_linux_amd64 -o /usr/bin/shfmt"
42+
- su - root -c "chmod +x /usr/bin/shfmt"
43+
# install shellcheck cli
44+
- su - root -c "curl -O -L https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz"
45+
- su - root -c "tar -xvf shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz && rm -rf shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz && mv shellcheck-v${SHELLCHECK_VERSION}/shellcheck /usr/bin/shellcheck && chmod +x /usr/bin/shellcheck"
46+
# install yamlfmt cli
47+
- su - root -c "curl -O -L https://github.com/google/yamlfmt/releases/download/v${YAMLFMT_VERSION}/yamlfmt_${YAMLFMT_VERSION}_Linux_x86_64.tar.gz"
48+
- su - root -c "tar -xvf yamlfmt_${YAMLFMT_VERSION}_Linux_x86_64.tar.gz && rm -rf yamlfmt_${YAMLFMT_VERSION}_Linux_x86_64.tar.gz && mv yamlfmt /usr/bin/yamlfmt && chmod +x /usr/bin/yamlfmt"
3749
# add non root user
3850
- useradd -m github --shell /bin/bash && usermod -aG docker github
3951
- su - github -c "mkdir -p /home/github/actions-runner"
4052
# install playwright
4153
- su - root -c "PLAYWRIGHT_BROWSERS_PATH=/home/github/.cache/ms-playwright PLAYWRIGHT_DOWNLOAD_HOST=https://storage.yandexcloud.net/playwright npx -y playwright@${PLAYWRIGHT_VERSION} install --with-deps chromium"
54+
- su - root -c "chown -R github:github /home/github/.cache"
4255
# remove DejaVuSans fonts
4356
- apt purge -y fonts-dejavu-core fonts-dejavu-mono
4457
# install github runner agent
4558
- export RUNNER_ARCH=x64
4659
- export RUNNER_TOKEN=$(yc lockbox payload get --id ${LOCKBOX_ID} --key ${LOCKBOX_KEY})
4760
- su - github -c "cd /home/github/actions-runner && curl -O -L https://github.com/actions/runner/releases/download/v${VERSION}/actions-runner-linux-$${RUNNER_ARCH}-${VERSION}.tar.gz"
4861
- su - github -c "cd /home/github/actions-runner && tar xzf ./actions-runner-linux-$${RUNNER_ARCH}-${VERSION}.tar.gz && rm -rf ./actions-runner-linux-$${RUNNER_ARCH}-${VERSION}.tar.gz"
49-
- su - github -c "cd /home/github/actions-runner && ./config.sh --unattended --url https://github.com/${OWNER} --token $${RUNNER_TOKEN} --name github-runner-${LABEL}-ind-${IND} --runnergroup default --work _work --labels cloud,${LABEL},${LABEL}-ind-${IND}"
62+
- su - github -c "cd /home/github/actions-runner && ./config.sh --unattended --url https://github.com/${OWNER} --token $${RUNNER_TOKEN} --name github-runner-${LABEL}-ind-${IND} --runnergroup ${RUNNER_GROUP} --replace --work _work --labels cloud,${LABEL},${LABEL}-ind-${IND}"
5063
- su - root -c "cd /home/github/actions-runner && ./svc.sh install github"
5164
- su - root -c "cd /home/github/actions-runner && ./svc.sh start"

0 commit comments

Comments
 (0)