Skip to content

Commit 4fa42c1

Browse files
feat: Branchs generate beta docker images and improves to dockerfile setup (#7)
1 parent 89a0f2f commit 4fa42c1

File tree

6 files changed

+110
-40
lines changed

6 files changed

+110
-40
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Beta docker on dev branch
2+
3+
on:
4+
push:
5+
# Sequence of patterns matched against refs/heads
6+
branches-ignore:
7+
- 'main'
8+
paths-ignore:
9+
- 'CODEOWNERS'
10+
- '**.md'
11+
- '.**'
12+
13+
jobs:
14+
release:
15+
name: Beta docker on dev branch
16+
runs-on: ubuntu-22.04
17+
18+
steps:
19+
- name: Checkout
20+
id: checkout
21+
# from https://github.com/actions/checkout/commits/main
22+
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707
23+
with:
24+
persist-credentials: false
25+
fetch-depth: 0
26+
27+
- name: Log in to the Container registry
28+
id: docker_login
29+
# from https://github.com/docker/login-action/commits/master
30+
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.PAT_GITHUB_PACKAGES }}
35+
36+
- name: Build and push Docker image
37+
id: docker_build_push
38+
# from https://github.com/docker/build-push-action/commits/master
39+
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5
40+
with:
41+
context: .
42+
push: true
43+
tags: |
44+
ghcr.io/${{ github.repository }}:beta-${{ github.ref_name }}
45+
labels: |
46+
maintainer=https://pagopa.it
47+
org.opencontainers.image.source=https://github.com/${{ github.repository }}

.hadolint.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignored:
2+
- DL3008
3+
- DL3009
4+
- DL3015
5+
- DL4006

Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# from https://hub.docker.com/_/ubuntu/tags?page=1&name=22.04
22
FROM ubuntu:22.04@sha256:965fbcae990b0467ed5657caceaec165018ef44a4d2d46c7cdea80a9dff0d1ea
33

4-
COPY install_script.sh install_script.sh
4+
WORKDIR /
55

6-
RUN bash install_script.sh
6+
COPY dockerfile-setup.sh dockerfile-setup.sh
7+
RUN bash dockerfile-setup.sh
78

8-
COPY entrypoint.sh /entrypoint.sh
9-
RUN chmod +x /entrypoint.sh
9+
COPY github-runner-entrypoint.sh /github-runner-entrypoint.sh
10+
RUN chmod +x /github-runner-entrypoint.sh
1011

12+
# changed user to avoid root user
1113
USER github
1214

13-
WORKDIR /
14-
1515
RUN whoami && \
1616
az --version && \
1717
kubectl --help && \
1818
helm --help && \
1919
yq --version
2020

21-
ENTRYPOINT ["/entrypoint.sh"]
21+
ENTRYPOINT ["/github-runner-entrypoint.sh"]

docker-compose.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3.9"
2+
services:
3+
github_runner:
4+
build: .
5+
environment:
6+
- GITHUB_REPOSITORY=${GITHUB_REPOSITORY}
7+
- GITHUB_TOKEN=${GITHUB_TOKEN}
8+
Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#!/usr/bin/env bash
22

3-
apt-get update && apt-get install -y curl git
4-
3+
echo "[INFO] Start apt get install base packages"
4+
5+
apt-get update \
6+
&& apt-get -y install curl git vim \
7+
&& apt-get -y install zip unzip \
8+
&& apt-get -y install ca-certificates curl wget apt-transport-https lsb-release gnupg \
9+
&& apt-get -y install jq \
10+
&& apt-get satisfy "python3-pip (<= 22.1)" -y
11+
# install jq from https://stedolan.github.io/jq/download/
12+
13+
#
14+
# Github Action runner
15+
#
16+
echo "[INFO] Install github action runner"
517
mkdir -p actions-runner
6-
cd actions-runner
18+
cd actions-runner || exit
19+
720
# from https://github.com/actions/runner/releases
821
GITHUB_RUNNER_VERSION="2.300.2"
922
GITHUB_RUNNER_VERSION_SHA="ed5bf2799c1ef7b2dd607df66e6b676dff8c44fb359c6fedc9ebf7db53339f0c"
@@ -14,13 +27,10 @@ rm actions-runner-linux-x64-${GITHUB_RUNNER_VERSION}.tar.gz
1427

1528
bash bin/installdependencies.sh
1629

17-
# install zip, unip
18-
19-
apt-get -y install zip unzip
20-
21-
# install az cli from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt#option-2-step-by-step-installation-instructions
22-
23-
apt-get -y install ca-certificates curl wget apt-transport-https lsb-release gnupg
30+
#
31+
# AZCLI
32+
#
33+
echo "[INFO] Install azcli"
2434

2535
curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
2636
AZ_REPO=$(lsb_release -cs)
@@ -30,36 +40,31 @@ apt-get update && apt-get -y install azure-cli
3040

3141
az config set extension.use_dynamic_install=yes_without_prompt
3242

33-
# install python-pip
34-
35-
apt-get -y install python-pip
36-
43+
#
44+
# KUBERNETES DEPENDENCIES
45+
#
3746
# install kubectl from https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-native-package-management
47+
echo "[INFO] Install kubernetes"
3848

3949
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
4050
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
4151

42-
apt-get update && apt-get -y install kubectl
43-
4452
# install helm from https://helm.sh/docs/intro/install/#from-apt-debianubuntu
45-
4653
curl https://baltocdn.com/helm/signing.asc | apt-key add -
4754
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | tee /etc/apt/sources.list.d/helm-stable-debian.list
4855

49-
apt-get update && apt-get -y install helm
50-
51-
# install jq from https://stedolan.github.io/jq/download/
52-
53-
apt-get update && apt-get -y install jq
56+
apt-get update \
57+
&& apt-get satisfy "kubectl (<=1.26.1)" -y \
58+
&& apt-get update && apt-get satisfy "helm (<=3.12.1)" -y
5459

5560
# install yq from https://github.com/mikefarah/yq#install
56-
5761
YQ_VERSION="v4.30.6"
5862
YQ_BINARY="yq_linux_amd64"
5963
wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY}.tar.gz -O - | tar xz && mv ${YQ_BINARY} /usr/bin/yq
6064

61-
###
62-
65+
#
66+
# USER CONFIGURATIONS
67+
#
6368
useradd github
6469
mkdir -p /home/github
6570
chown -R github:github /home/github

entrypoint.sh renamed to github-runner-entrypoint.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
INTERACTIVE="FALSE"
4-
if [ "$(echo $INTERACTIVE_MODE | tr '[:upper:]' '[:lower:]')" == "true" ]; then
4+
if [ "$(echo "$INTERACTIVE_MODE" | tr '[:upper:]' '[:lower:]')" == "true" ]; then
55
INTERACTIVE="TRUE"
66
fi
77

@@ -20,7 +20,8 @@ if [ -z "$GITHUB_REPOSITORY_BANNER" ]; then
2020
fi
2121

2222
if [ -z "$RUNNER_NAME" ]; then
23-
export RUNNER_NAME="$(hostname)"
23+
RUNNER_NAME="$(hostname)"
24+
export RUNNER_NAME
2425
fi
2526

2627
if [ -z "$WORK_DIR" ]; then
@@ -30,20 +31,24 @@ fi
3031
# Calculate runner replacement policy.
3132
REPLACEMENT_POLICY="\n\n\n"
3233
REPLACEMENT_POLICY_LABEL="FALSE"
33-
if [ "$(echo $REPLACE_EXISTING_RUNNER | tr '[:upper:]' '[:lower:]')" == "true" ]; then
34+
if [ "$(echo "$REPLACE_EXISTING_RUNNER" | tr '[:upper:]' '[:lower:]')" == "true" ]; then
3435
REPLACEMENT_POLICY="Y\n\n"
3536
REPLACEMENT_POLICY_LABEL="TRUE"
3637
fi
3738

3839
# Configure runner interactively, or with the given replacement policy.
39-
printf "Configuring GitHub Runner for $GITHUB_REPOSITORY_BANNER\n"
40-
printf "\tRunner Name: $RUNNER_NAME\n\tWorking Directory: $WORK_DIR\n\tReplace Existing Runners: $REPLACEMENT_POLICY_LABEL\n"
40+
printf "Configuring GitHub Runner for %s\n\t" "$GITHUB_REPOSITORY_BANNER"
41+
printf "Runner Name: %s\n\t" "$RUNNER_NAME"
42+
printf "Working Directory: %s\n\t" "$WORK_DIR"
43+
printf "Replace Existing Runners: %s\n" "$REPLACEMENT_POLICY_LABEL"
44+
45+
# actions-runner is a folder inside the github runner zip
4146
if [ "$INTERACTIVE" == "FALSE" ]; then
42-
echo -ne "$REPLACEMENT_POLICY" | ./actions-runner/config.sh --url $GITHUB_REPOSITORY --token $GITHUB_TOKEN --agent $RUNNER_NAME --work $WORK_DIR --labels $LABELS --disableupdate
47+
echo -ne "$REPLACEMENT_POLICY" | ./actions-runner/config.sh --url "$GITHUB_REPOSITORY" --token "$GITHUB_TOKEN" --name "$RUNNER_NAME" --work "$WORK_DIR" --labels "$LABELS" --disableupdate
4348
else
44-
./actions-runner/config.sh --url $GITHUB_REPOSITORY --token $GITHUB_TOKEN --agent $RUNNER_NAME --work $WORK_DIR --labels $LABELS --disableupdate
49+
./actions-runner/config.sh --url "$GITHUB_REPOSITORY" --token "$GITHUB_TOKEN" --name "$RUNNER_NAME" --work "$WORK_DIR" --labels "$LABELS" --disableupdate
4550
fi
4651

4752
# Start the runner.
48-
printf "Executing GitHub Runner for $GITHUB_REPOSITORY\n"
53+
printf "Executing GitHub Runner for %s\n" "$GITHUB_REPOSITORY"
4954
./actions-runner/run.sh

0 commit comments

Comments
 (0)