-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Create Cluster with Registry | ||
|
||
on: | ||
push: {} | ||
|
||
jobs: | ||
setup-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker registry | ||
run: | | ||
docker network create kind || true | ||
docker run -d --network kind --name registry -p 5000:5000 registry:2 | ||
- name: Set up Kind cluster | ||
uses: helm/kind-action@v1.7.0 | ||
with: | ||
version: v0.20.0 | ||
env: | ||
KIND_EXPERIMENTAL_DOCKER_NETWORK: kind | ||
|
||
- name: Connect Kind to the Docker registry | ||
run: | | ||
cat <<EOF > kind-config.yaml | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
kind: Cluster | ||
containerdConfigPatches: | ||
- | | ||
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"] | ||
endpoint = ["http://registry:5000"] | ||
EOF | ||
kind create cluster --config kind-config.yaml | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 | ||
with: | ||
images: localhost:5000/ctferio/chall-manager | ||
|
||
- name: Git commit date | ||
id: infos | ||
run: | | ||
# output date per RFC 3339 | ||
date="$(git log -1 --format=%cd --date=format:%Y-%m-%dT%H:%M:%SZ)" | ||
echo "date=$date" >> "$GITHUB_OUTPUT" | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc # v6.11.0 | ||
id: build | ||
with: | ||
push: true | ||
tags: ${{ github.sha }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
file: Dockerfile.chall-manager | ||
build-args: | | ||
VERSION=${{ github.sha }} | ||
COMMIT=${{ github.sha }} | ||
DATE=${{ steps.infos.outputs.date }} | ||
- name: Deploy application to Kind | ||
run: | | ||
kubectl apply -f - <<EOF | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-app | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: my-app | ||
template: | ||
metadata: | ||
labels: | ||
app: my-app | ||
spec: | ||
containers: | ||
- name: my-app | ||
image: localhost:5000/ctferio/chall-manager:${{ github.sha }} | ||
ports: | ||
- containerPort: 8080 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: my-app | ||
spec: | ||
selector: | ||
app: my-app | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 8080 | ||
EOF | ||
- name: Verify deployment | ||
run: | | ||
kubectl rollout status deployment/my-app |