Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/templates/docker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docker build
description: "Build the specified docker image and publishes it for the workflow"
inputs:
path:
description: "The path of the dockerfile to be built"
required: true
filepath:
description: "If the dockerfile is in a different directory then the context it needs to be specified here"
required: false
tags:
description: "The tag(s) for building the image"
required: true
runs:
using: composite
steps:
- name: Build the container
id: img
shell: bash
env:
CONTEXT_PATH: ${{ inputs.path }}
FILE_PATH: ${{ inputs.filepath }}
TAGS: ${{ inputs.tags }}
run: |
bash $GITHUB_ACTION_PATH/build.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to stick to the env var, this line makes more sense to me:

Suggested change
bash $GITHUB_ACTION_PATH/build.sh
bash $ACTION_PATH/build.sh

BTW do we need this env var? This should work too:

Suggested change
bash $GITHUB_ACTION_PATH/build.sh
bash ${{ github.action_path }}/build.sh

Copy link
Collaborator Author

@benjoe1126 benjoe1126 May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing the ACTION_PATH env var, can't quite remember why it was there to begin with, but it was not used anyway.
The GITHUB_ACTION_PATH has to stay tho, as ${{ github.action_path }} is a github context directive and can't be interpreted by the script executed on the runner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GITHUB_ACTION_PATH has to stay tho, as ${{ github.action_path }} is a github context directive and can't be interpreted by the script executed on the runner.

The shell script does not use the env var; using the context directive in this line is fine as the GHA runner reads it.

IMAGE_NAME=$(echo "${TAGS}" | cut -d : -f1)
echo ${IMAGE_NAME}
echo "name=${IMAGE_NAME}" >> $GITHUB_ENV

- name: Publish image
uses: actions/upload-artifact@v4
with:
name: ${{ env.name }}
path: ${{ inputs.path }}/images
9 changes: 9 additions & 0 deletions .github/templates/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd "${CONTEXT_PATH}" || exit 1
if [[ -z "${FILE_PATH}" ]]; then
docker build -t "${TAGS}" .
else
docker build -f "${FILE_PATH}" -t "${TAGS}" .
fi
IMAGE_NAME=$(echo "${TAGS}" | cut -d : -f1)
mkdir images
docker image save -o "images/${IMAGE_NAME}" "${TAGS}"
16 changes: 16 additions & 0 deletions .github/templates/go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test go
description: "Tests the go files with the given arguments"
inputs:
tests:
description: "The project(s) that should be tested (kubernetes tests only), if you want to run multiple, provide their name separated with spaces"
required: true
default: 'all'
runs:
using: composite
steps:
- name: Test go program
shell: bash
env:
PROJECT_PATH: ${{ github.workspace }}
TESTS: ${{ inputs.tests }}
run: bash ${{ github.action_path }}/main.sh
17 changes: 17 additions & 0 deletions .github/templates/go/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cd "${PROJECT_PATH}"/99-labs/code || exit 1
if [ "${TESTS}" = "all" ]; then
TESTS=("helloworld" "splitdim" "kvstore")
fi

for TEST in ${TESTS[@]}; do
pushd . > /dev/null
cd ${TEST} || exit 1
go mod download
go test ./... --tags=kubernetes --count 1
ret=$?
if [[ $ret -ne 0 ]]; then
exit $ret
fi
popd > /dev/null
done

44 changes: 44 additions & 0 deletions .github/templates/kind-cluster-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Kind setup"
description: "Installs and sets up a running kind cluster, including the cloud-provider-kind and istio for service mesh"
inputs:
istio:
description: "A flag weather to start the istio service mesh"
default: 'false'
required: false
runs:
using: composite
steps:
- name: Install kind and start cluster
uses: helm/kind-action@v1
with:
cluster_name: test
kubectl_version: 'v1.30.4'

- name: Load images to node(s)
shell: bash
run: |
for i in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ':test'); do
kind load docker-image -n test ${i}
done

- name: Install cloud-provider-kind and start in background
shell: bash
env:
VERSION: 0.6.0
run: |
curl -L https://github.com/kubernetes-sigs/cloud-provider-kind/releases/download/v${VERSION}/cloud-provider-kind_${VERSION}_linux_amd64.tar.gz \
| tar -xz
sudo mv cloud-provider-kind /usr/local/bin/
sudo chmod +x /usr/local/bin/cloud-provider-kind
cloud-provider-kind &

- name: Start istio service mesh
if: inputs.istio == 'true'
shell: bash
run: |
curl -L https://istio.io/downloadIstio | sh -
cd istio*
kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.0.0" | kubectl apply -f -
bin/istioctl install --set profile=minimal -y
kubectl label namespace default istio-injection=enabled --overwrite

18 changes: 18 additions & 0 deletions .github/templates/load-images/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Load built images
description: "Loads the previously built images and deletes the artifacts after"
runs:
using: composite
steps:
- name: Load images
shell: bash
run: |
for i in $(ls images); do
docker image load < "images/$i"
done
- name: Delete artifacts
uses: geekyeggo/delete-artifact@v5
with:
useGlob: 'true'
name: '*'
failOnError: false

36 changes: 36 additions & 0 deletions .github/templates/minikube-cluster-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Minikube cluster setup
description: "Sets up a minikube cluster, starts the minikube tunnel and loads the necessery images"
inputs:
istio:
description: "Flag if istio should be installed"
default: 'false'
runs:
using: composite
steps:
- name: Start minikube
uses: medyagh/setup-minikube@latest
with:
driver: docker
container-runtime: containerd
wait: all
cache: true

- name: Start minikube tunnel
shell: bash
run: minikube tunnel &> /dev/null &

- name: Load images
shell: bash
run: |
for i in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ':test'); do
minikube image load ${i}
done
- name: Start istio service mesh
if: inputs.istio == 'true'
shell: bash
run: |
curl -L https://istio.io/downloadIstio | sh -
cd istio*
kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.0.0" | kubectl apply -f -
bin/istioctl install --set profile=minimal -y
kubectl label namespace default istio-injection=enabled --overwrite
11 changes: 11 additions & 0 deletions .github/templates/test-istio/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Test istio
description: "Tests the istio service mesh"
runs:
using: composite
steps:
- name: Test istio service mesh program
shell: bash
run: bash ${{ github.action_path }}/main.sh
env:
PROJECT_PATH: ${{ github.workspace }}
ACTION_PATH: ${{ github.action_path }}
7 changes: 7 additions & 0 deletions .github/templates/test-istio/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cd ${PROJECT_PATH}/99-labs/code/splitdim/deploy || exit 1
kubectl apply -f kubernetes-istio.yaml
bash ${ACTION_PATH}/wait.sh
export EXTERNAL_IP=$(kubectl get service splitdim-istio -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export EXTERNAL_PORT=80
cd ..
go test ./... --tags=httphandler,api,localconstructor,reset,transfer,accounts,clear -v -count 1
14 changes: 14 additions & 0 deletions .github/templates/test-istio/wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SECONDS=0
while true; do
kubectl get svc #for debug
IP=$(kubectl get service splitdim-istio -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [[ ! -n "$IP" ]]; then
if (( SECONDS == 15));then
exit 1
fi
SECONDS=$(( SECONDS + 1 ))
sleep 1
else
exit 0
fi
done
46 changes: 46 additions & 0 deletions .github/workflows/test-homeworks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test Homeworks
on:
push:
branches:
- master
paths-ignore:
- 99-labs
- env
- internals
- .gitignore
workflow_dispatch:
inputs:
report:
type: boolean
description: If true then the pipeline creates a report json used for final evaluation and doesn't execute regular tests
default: false
jobs:
test-homeworks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '1'
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '^1.24.0'
- name: Test homeworks
if: ! inputs.report || github.event_name == 'push'
run: |
export STUDENT_ID="$(grep -v -e '^$' STUDENT_ID)" # set the student_id used for test generation
make generate # generate the tests
make test
- name: Generate report
if: inputs.report
run: |
export STUDENT_ID="$(grep -v -e '^$' STUDENT_ID)" # set the student_id used for test generation
make generate
make report
- name: Artifact report
if: inputs.report
uses: actions/upload-artifact@v4
with:
name: 'report'
path: '*-report.json'

78 changes: 78 additions & 0 deletions .github/workflows/test-labs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Test
on:
workflow_dispatch:
inputs:
kube-distro:
type: choice
description: "The type of kubernetes distribution to use, i.e minikube, kind"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Note: on the long run we will enable just one option to simplify debugging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is: we use minikube now, but kind is more performant.

options:
- minikube
- kind
default: kind
required: false

istio-ready:
type: boolean
description: "Set to true if istio can be tested, leave false otherwise"
required: false

kubernetes-tests:
type: string
description: "Kubernetes tests to be run. Options: 'helloworld' 'splitdim', 'kvstore', 'all'. if you want to run multiple, provide them separated with spaces (e.g., 'kvstore splitdim'); 'all' means execute all tests"
default: 'all'
required: false


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
image-root: ['helloworld','kvstore', 'splitdim']
steps:
- uses: actions/checkout@v4
- uses: ./.github/templates/docker
with:
path: ${{ github.workspace }}/99-labs/code/${{ matrix.image-root }}
filepath: ${{ github.workspace }}/99-labs/code/${{ matrix.image-root }}/deploy/Dockerfile
tags: ${{ matrix.image-root }}:test
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '1'
- uses: actions/download-artifact@v4
with:
path: images
merge-multiple: 'true'
- name: Load all docker images
uses: ./.github/templates/load-images

- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '^1.23.0'

- name: Start kind cluster
if: github.event.inputs.kube-distro == 'kind'
uses: ./.github/templates/kind-cluster-setup
with:
istio: 'true'

- name: Start minikube cluster
if: github.event.inputs.kube-distro == 'minikube'
uses: ./.github/templates/minikube-cluster-setup
with:
istio: 'true'


- name: Test istio
if: github.event.inputs.istio-ready == true
uses: ./.github/templates/test-istio

- name: Test go project
uses: ./.github/templates/go
with:
tests: ${{ github.event.inputs.kubernetes-tests }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
*.out

.vscode/*

.idea
2 changes: 1 addition & 1 deletion 24-generics/01-sorting/.README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ The sorting should satisfy the following requirements:
An example for the usage:
{{ index . "example" }}

Place your code into the file `exercise.go` near the placeholder `// INSERT YOUR CODE HERE`.
Place your code into the file `exercise.go` near the placeholder `// INSERT YOUR CODE HERE`.
10 changes: 0 additions & 10 deletions 99-labs/code/helloworld/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package main

import (
"context"
"fmt"
"io"
"net"
Expand All @@ -17,17 +16,10 @@ import (
)

func TestHelloWorldKubernetes(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// clean up cluster
execCmd(t, "kubectl", "delete", "-f", "deploy/kubernetes-deployment.yaml")
execCmd(t, "kubectl", "delete", "-f", "deploy/kubernetes-service.yaml")

// build the container image
execCmd(t, "minikube", "image", "build", "-t", "helloworld", "-f", "deploy/Dockerfile", ".")
go execCmd(t, "minikube", "tunnel")

// redeploy
execCmd(t, "kubectl", "apply", "-f", "deploy/kubernetes-deployment.yaml")
execCmd(t, "kubectl", "apply", "-f", "deploy/kubernetes-service.yaml")
Expand All @@ -37,8 +29,6 @@ func TestHelloWorldKubernetes(t *testing.T) {

ip, _ := execCmd(t, "kubectl", "get", "service", "helloworld", "-o", `jsonpath="{.status.loadBalancer.ingress[0].ip}"`)
if ip == "" {
// make sure minikube tunnel is running if no public IP exists
execCmdContext(ctx, t, "minikube", "tunnel")
// may take a while
time.Sleep(10 * time.Second)
ip, _ = execCmd(t, "kubectl", "get", "service", "helloworld", "-o", `jsonpath="{.status.loadBalancer.ingress[0].ip}"`)
Expand Down
Loading
Loading