Skip to content

Commit

Permalink
feat: Enable Kubelogin setup (#8)
Browse files Browse the repository at this point in the history
* kubelogin installation added

* try beta docker

* removed release-docker-branch

* minor fix

* file setup: allow external values (from docker) and fix helm install

* dockerfile: added env variables for component versions
  • Loading branch information
diegolagospagopa committed Mar 1, 2023
1 parent 4fa42c1 commit 4dc2f62
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beta-docker-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT_GITHUB_PACKAGES }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
id: docker_build_push
Expand Down
48 changes: 0 additions & 48 deletions .github/workflows/release-docker-branch.yml

This file was deleted.

6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# from https://hub.docker.com/_/ubuntu/tags?page=1&name=22.04
FROM ubuntu:22.04@sha256:965fbcae990b0467ed5657caceaec165018ef44a4d2d46c7cdea80a9dff0d1ea

ENV ENV_GITHUB_RUNNER_VERSION="2.302.1"
ENV ENV_GITHUB_RUNNER_VERSION_SHA=3d357d4da3449a3b2c644dee1cc245436c09b6e5ece3e26a05bb3025010ea14d
ENV ENV_YQ_VERSION="v4.30.6"
ENV ENV_KUBELOGIN_VERSION=0.0.27

WORKDIR /

COPY dockerfile-setup.sh dockerfile-setup.sh
Expand All @@ -15,6 +20,7 @@ USER github
RUN whoami && \
az --version && \
kubectl --help && \
kubelogin --version && \
helm --help && \
yq --version

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: "3.9"
services:
github_runner:
build: .
# build: .
image: ghcr.io/pagopa/github-self-hosted-runner-azure:beta-kubelogin-setup
environment:
- GITHUB_REPOSITORY=${GITHUB_REPOSITORY}
- GITHUB_TOKEN=${GITHUB_TOKEN}


52 changes: 40 additions & 12 deletions dockerfile-setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

echo "[INFO] Start apt get install base packages"
echo " Start apt get install base packages"

apt-get update \
&& apt-get -y install curl git vim \
Expand All @@ -10,41 +10,48 @@ apt-get update \
&& apt-get satisfy "python3-pip (<= 22.1)" -y
# install jq from https://stedolan.github.io/jq/download/

# Test whoami
whoami

echo "✅ whoami > run as expected"

#
# Github Action runner
#
echo "[INFO] Install github action runner"
mkdir -p actions-runner
cd actions-runner || exit

# from https://github.com/actions/runner/releases
GITHUB_RUNNER_VERSION="2.300.2"
GITHUB_RUNNER_VERSION_SHA="ed5bf2799c1ef7b2dd607df66e6b676dff8c44fb359c6fedc9ebf7db53339f0c"
GITHUB_RUNNER_VERSION="${ENV_GITHUB_RUNNER_VERSION:-2.302.1}"
GITHUB_RUNNER_VERSION_SHA="${ENV_GITHUB_RUNNER_VERSION_SHA:-3d357d4da3449a3b2c644dee1cc245436c09b6e5ece3e26a05bb3025010ea14d}"
curl -o actions-runner-linux-x64-${GITHUB_RUNNER_VERSION}.tar.gz -L https://github.com/actions/runner/releases/download/v${GITHUB_RUNNER_VERSION}/actions-runner-linux-x64-${GITHUB_RUNNER_VERSION}.tar.gz
echo "${GITHUB_RUNNER_VERSION_SHA} actions-runner-linux-x64-${GITHUB_RUNNER_VERSION}.tar.gz" | sha256sum -c
tar xzf ./actions-runner-linux-x64-${GITHUB_RUNNER_VERSION}.tar.gz
rm actions-runner-linux-x64-${GITHUB_RUNNER_VERSION}.tar.gz

bash bin/installdependencies.sh
echo "✅ Installed > github action runner"

#
# AZCLI
#
echo "[INFO] Install azcli"

curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list

apt-get update && apt-get -y install azure-cli
apt-get update \
&& apt-get -y install azure-cli

az config set extension.use_dynamic_install=yes_without_prompt

## Test azcli
az --version
echo "✅ Installed > azcli"

#
# KUBERNETES DEPENDENCIES
#
# install kubectl from https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-native-package-management
echo "[INFO] Install kubernetes"

curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list
Expand All @@ -53,14 +60,35 @@ echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https:/
curl https://baltocdn.com/helm/signing.asc | apt-key add -
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | tee /etc/apt/sources.list.d/helm-stable-debian.list

apt-get update \
&& apt-get satisfy "kubectl (<=1.26.1)" -y \
&& apt-get update && apt-get satisfy "helm (<=3.12.1)" -y
apt-get update
echo "✅ Configure kubernetes & Helm for installation"


apt-get satisfy "kubectl" -y
## Test kubectl
kubectl --help
echo "✅ Installed kubernetes"

apt-get satisfy "helm" -y
## Test helm
helm --help
echo "✅ Installed kubernetes"

# install yq from https://github.com/mikefarah/yq#install
YQ_VERSION="v4.30.6"
YQ_VERSION="${ENV_YQ_VERSION:-v4.30.6}"
YQ_BINARY="yq_linux_amd64"
wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY}.tar.gz -O - | tar xz && mv ${YQ_BINARY} /usr/bin/yq
echo "✅ Installed YQ"

## Test YQ
yq --version

# Kubelogin install (use kubectl to install packages)
KUBELOGIN_VERSION="${ENV_KUBELOGIN_VERSION:-0.0.26}"
az aks install-cli --kubelogin-version "${KUBELOGIN_VERSION}"
## Test kubelogin
kubelogin --version
echo "✅ Installed kubelogin"

#
# USER CONFIGURATIONS
Expand Down

0 comments on commit 4dc2f62

Please sign in to comment.