|
1 | | -# goApiPipelineExample |
2 | | -Working pipeline |
| 1 | +# pipeline-example |
| 2 | + |
| 3 | +example for jamf |
| 4 | +docker desktop |
| 5 | +run in kind |
| 6 | +kind create cluster --name local-test |
| 7 | + |
| 8 | +kubectl get pods |
| 9 | + |
| 10 | +# π§© Basic API Pipeline Example |
| 11 | + |
| 12 | +_A lightweight Go web service with automated Kubernetes deployment using Kind, Helm, and GitHub Actions._ |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## π Overview |
| 17 | + |
| 18 | +This repository demonstrates a full CI/CD workflow for a simple Go-based API deployed to a local **Kind (Kubernetes in Docker)** cluster. |
| 19 | +The GitHub Actions pipeline handles building, pushing, deploying, and verifying your application end-to-end β making it easy to reproduce locally or debug via **tmate**. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## What's it do? |
| 24 | + |
| 25 | +A minimal Go API running on port `8080`: |
| 26 | + |
| 27 | +```go |
| 28 | +func main() { |
| 29 | + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 30 | + fmt.Fprint(w, "Hello World") |
| 31 | + }) |
| 32 | + http.ListenAndServe(":8080", nil) |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +When running, http://localhost:8080 |
| 37 | + |
| 38 | +βοΈ Prerequisites |
| 39 | + |
| 40 | +Install these tools locally to mirror the CI environment: |
| 41 | +Tool - Version - Install |
| 42 | +Go β₯ 1.22 - golang.org/dl |
| 43 | +Docker β₯ 24 - docs.docker.com (I use Docker Desktop) |
| 44 | +Kubectl β₯ 1.30 - kubernetes.io |
| 45 | +Helm β₯ 3.14 - helm.sh |
| 46 | +Kind β₯ 0.23 - kind.sigs.k8s.io |
| 47 | + |
| 48 | +# Running the App Locally |
| 49 | + |
| 50 | +## Run locally |
| 51 | + |
| 52 | +Pull the repo down and cd into it then run it locally to verify it works |
| 53 | + |
| 54 | +``` |
| 55 | +go run main.go |
| 56 | +``` |
| 57 | + |
| 58 | +## The included workflow automates the full build β deploy β verify cycle. |
| 59 | + |
| 60 | +## Make sure Kubernetes is enabled in Docker |
| 61 | + |
| 62 | +π .github/workflows/ci.yml |
| 63 | +Pipeline steps: |
| 64 | +Build & Test Go App |
| 65 | +Build & Push Docker Image β Builds and pushes to Docker Hub. |
| 66 | +Create Kind Cluster β Spins up a temporary Kubernetes cluster inside GitHub Actions. |
| 67 | +Export kubeconfig β Ensures Helm and kubectl point to the correct cluster. |
| 68 | +Deploy Helm Chart |
| 69 | +Verify API Response β Uses kubectl port-forward + curl to confirm Hello World. |
| 70 | +(Optional) action-tmate β Opens a live debugging session for interactive testing. [link](https://github.com/mxschmitt/action-tmate?tab=readme-ov-file) |
| 71 | + |
| 72 | +π Required GitHub Infp |
| 73 | +Name Description |
| 74 | +DOCKERHUB_USERNAME - Your Docker Hub username (new variable) |
| 75 | +DOCKERHUB_TOKEN - Docker Hub access token for docker push (new secret) |
| 76 | +Public SSH Key - Optional, for tMate validation |
| 77 | + |
| 78 | +# Trigger Workflow |
| 79 | + |
| 80 | +1. Make a change to a file and push it up to Github. Create a new PR and the workflow will kick off. |
| 81 | + |
| 82 | + - When the workflow gets to the 'deploy-and-validate' stage, click into the workflow details. |
| 83 | + - Inside, wait for 'Start tMate Session' to start |
| 84 | + |
| 85 | + - Click in, and wait for a series of ssh code to show up, should look similar to: |
| 86 | + πΉ How to Connect |
| 87 | + When the workflow reaches the tmate step, it prints something like: |
| 88 | + SSH: ssh abcdefgh@nyc1.tmate.io |
| 89 | + |
| 90 | + SSH URL: Connect from your local terminal: |
| 91 | + `ssh abcdefgh@nyc1.tmate.io` |
| 92 | + |
| 93 | + - πΉ Once Inside tmate |
| 94 | + Check your pods: |
| 95 | + `kubectl get pods` |
| 96 | + |
| 97 | + Run: `kubectl port-forward deployment/pipeline-example 9091:8080 &` |
| 98 | + Wait a couple of seconds, then run: `curl http://localhost:9091` |
| 99 | + |
| 100 | + You should see a 'Hello World' returned to you. |
| 101 | + To close the instance, run `exit`. This will also finish your pipeline. |
| 102 | + You the pipeline will continue to run until you cancel it you dont use the tMate option. |
| 103 | + |
| 104 | +π§Ή Cleanup |
| 105 | +To reset your environment: |
| 106 | +kind delete cluster --name local-test |
| 107 | +docker image rm USERNAME/pipeline_example:latest |
| 108 | + |
| 109 | +π Troubleshooting |
| 110 | +Issue - Cause - Fix |
| 111 | +`port already in use` - Existing forward active `pkill -f "kubectl port-forward"` |
| 112 | + |
| 113 | +## Structure |
| 114 | + |
| 115 | +```. |
| 116 | +βββ main.go |
| 117 | +βββ Dockerfile |
| 118 | +βββ pipeline-example/ |
| 119 | +β ββ |
| 120 | +β βββ Chart.yaml |
| 121 | +β βββ templates/ |
| 122 | +β β βββ deployment.yaml |
| 123 | +β β βββ service.yaml |
| 124 | +β βββ values.yaml |
| 125 | +βββ .github/ |
| 126 | + βββ workflows/ |
| 127 | + βββ ci.yml |
| 128 | +``` |
| 129 | + |
| 130 | +π Summary |
| 131 | + |
| 132 | +This project is a simple, reproducible template for: |
| 133 | +Building and deploying a Go API to Kubernetes. |
| 134 | +Managing deployments with Helm. |
| 135 | +Automating CI/CD with GitHub Actions. |
| 136 | +Debugging live clusters with action-tmate. |
0 commit comments