From 99d52dae752c475afd9fd8136227f57f43ac7c5a Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:14:44 +0200 Subject: [PATCH 01/20] Updating readme file. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b7..394c427debe 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,5 @@ go build -o notely && ./notely *This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! + +MYNAME \ No newline at end of file From e5397dceccd32b50ae32e8189c7357f868779077 Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:21:53 +0200 Subject: [PATCH 02/20] Added CI file. --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..664032071d1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.26.0" + + - name: Force Failure + run: (exit 1) \ No newline at end of file From d913dd5117056a70bce66cc2799fcd73429db699 Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:24:55 +0200 Subject: [PATCH 03/20] Modified CI file. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 664032071d1..d64b8281507 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.26.0" - - name: Force Failure - run: (exit 1) \ No newline at end of file + - name: Check Go version + run: go version \ No newline at end of file From fe2077bd188ff539a9c0813d664b27581a5e7a8a Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:34:08 +0200 Subject: [PATCH 04/20] Modifying CI yml file. --- internal/auth/get_api_key_test.go | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 internal/auth/get_api_key_test.go diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..ffbfb56ce21 --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,73 @@ +package auth + +import ( + "errors" + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headers http.Header + wantKey string + wantErr error + wantErrMsg string // used when we only care about error text, not a sentinel + }{ + { + name: "valid api key", + headers: http.Header{"Authorization": []string{"ApiKey abc123"}}, + wantKey: "abc123", + wantErr: nil, + }, + { + name: "missing authorization header", + headers: http.Header{}, + wantKey: "", + wantErr: ErrNoAuthHeaderIncluded, + }, + { + name: "malformed header - no space", + headers: http.Header{"Authorization": []string{"ApiKeyabc123"}}, + wantKey: "", + wantErrMsg: "malformed authorization header", + }, + { + name: "malformed header - wrong prefix", + headers: http.Header{"Authorization": []string{"Bearer abc123"}}, + wantKey: "", + wantErrMsg: "malformed authorization header", + }, + { + name: "malformed header - only prefix, no key", + headers: http.Header{"Authorization": []string{"ApiKey"}}, + wantKey: "", + wantErrMsg: "malformed authorization header", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotKey, gotErr := GetAPIKey(tt.headers) + + if gotKey != tt.wantKey { + t.Errorf("got key %q, want %q", gotKey, tt.wantKey) + } + + switch { + case tt.wantErr != nil: + if !errors.Is(gotErr, tt.wantErr) { + t.Errorf("got err %v, want %v", gotErr, tt.wantErr) + } + case tt.wantErrMsg != "": + if gotErr == nil || gotErr.Error() != tt.wantErrMsg { + t.Errorf("got err %v, want message %q", gotErr, tt.wantErrMsg) + } + default: + if gotErr != nil { + t.Errorf("got unexpected err %v", gotErr) + } + } + }) + } +} \ No newline at end of file From f897ceb98f84e06218afb1e97e3618a88cd1c9a6 Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:34:37 +0200 Subject: [PATCH 05/20] Modifying CI yml file. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d64b8281507..fa8b33cad09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Check Go version - run: go version \ No newline at end of file + run: go test ./... \ No newline at end of file From f566447ce44be928ea7134aa23f30995b5e52f9f Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:37:10 +0200 Subject: [PATCH 06/20] Updating CI file. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa8b33cad09..c373db7fdca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Check Go version - run: go test ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From 819eb3fb7a26c64a1262ebbd6eec76e59a6214fb Mon Sep 17 00:00:00 2001 From: kresko Date: Sat, 8 Aug 2026 21:42:01 +0200 Subject: [PATCH 07/20] Updating readme file. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 394c427debe..996d46be225 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![badge](https://github.com/kresko/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) + # learn-cicd-starter (Notely) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). From 57cf1237fbfadc45c68a8398aa01ea43c84d4268 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:22:23 +0200 Subject: [PATCH 08/20] Updating CI file. --- .github/workflows/ci.yml | 16 ++++++++++++++++ internal/auth/get_api_key_test.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c373db7fdca..867389144b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,22 @@ jobs: name: Tests runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.26.0" + + - name: Check Go version + run: go test -cover ./... + + style: + name: Style + runs-on: ubuntu-latest + steps: - name: Check out code uses: actions/checkout@v6 diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go index ffbfb56ce21..773af59b94e 100644 --- a/internal/auth/get_api_key_test.go +++ b/internal/auth/get_api_key_test.go @@ -70,4 +70,4 @@ func TestGetAPIKey(t *testing.T) { } }) } -} \ No newline at end of file +} From b9ee1b11f9bb476f3828ecf194b1ff0e3cc49cb8 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:26:50 +0200 Subject: [PATCH 09/20] Updating CI file. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 867389144b1..1b63ff6a92e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,5 +34,5 @@ jobs: with: go-version: "1.26.0" - - name: Check Go version - run: go test -cover ./... \ No newline at end of file + - name: Check formating + run: test -z $(go fmt ./...) \ No newline at end of file From 4f4a77523a2f36f6ac07b70319ca3e2fb9072a92 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:31:46 +0200 Subject: [PATCH 10/20] Modified CI file. --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b63ff6a92e..a80a71a9199 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,4 +35,7 @@ jobs: go-version: "1.26.0" - name: Check formating - run: test -z $(go fmt ./...) \ No newline at end of file + run: test -z $(go fmt ./...) + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest \ No newline at end of file From 60f739f2bc810353285e7269bbc8945da029b70b Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:33:35 +0200 Subject: [PATCH 11/20] Testing main.go file. --- main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.go b/main.go index 19d7366c5f7..e546112a05a 100644 --- a/main.go +++ b/main.go @@ -96,3 +96,8 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } + +func unused() { + // this function does nothing + // and is called nowhere +} \ No newline at end of file From 46a7cb79e69752822e244539e2d96c9e678a1681 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:34:28 +0200 Subject: [PATCH 12/20] Testing main.go file. --- main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.go b/main.go index e546112a05a..dd9f84f90ea 100644 --- a/main.go +++ b/main.go @@ -95,9 +95,4 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) -} - -func unused() { - // this function does nothing - // and is called nowhere } \ No newline at end of file From d07c77a29fabd61552481cb1967e697d03fe1ab1 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:38:36 +0200 Subject: [PATCH 13/20] Testing main.go file. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index dd9f84f90ea..19d7366c5f7 100644 --- a/main.go +++ b/main.go @@ -95,4 +95,4 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) -} \ No newline at end of file +} From 8f09ac50a3ec252fd23675433456843a54ec154b Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:45:37 +0200 Subject: [PATCH 14/20] Modified CI yml file. --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a80a71a9199..7fd14a44073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,12 @@ jobs: - name: Check Go version run: go test -cover ./... + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run gosec + run: gosec ./... + style: name: Style runs-on: ubuntu-latest From 90f381282c8f2f97017d53be0949c7e8bca98585 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 18:57:29 +0200 Subject: [PATCH 15/20] Fixing security issues. --- json.go | 4 +++- main.go | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e18..0f8075d808a 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,7 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - w.Write(dat) + if _, err := w.Write(dat); err != nil { + log.Printf("Error writing response: %s", err) + } } diff --git a/main.go b/main.go index 19d7366c5f7..3ef3c41c832 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,8 @@ import ( "log" "net/http" "os" + "strconv" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -34,6 +36,10 @@ func main() { if port == "" { log.Fatal("PORT environment variable is not set") } + portNum, err := strconv.Atoi(port) + if err != nil { + log.Fatal("PORT environment variable must be numeric") + } apiCfg := apiConfig{} @@ -89,10 +95,11 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadHeaderTimeout: 5 * time.Second, } - log.Printf("Serving on port: %s\n", port) + log.Printf("Serving on port: %d\n", portNum) log.Fatal(srv.ListenAndServe()) } From 24007d547ef5e20a954e1a9057d439e5fac10012 Mon Sep 17 00:00:00 2001 From: kresko Date: Sun, 9 Aug 2026 20:04:30 +0200 Subject: [PATCH 16/20] Added CD yml file. --- .github/workflows/cd.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000000..22aa946bf18 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,22 @@ +name: cd + +on: + push: + branches: [main] + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.26.0" + + - name: Build + run: ./scripts/buildprod.sh \ No newline at end of file From a0dcd6c3b452dc181d85cf39269fd549373b8554 Mon Sep 17 00:00:00 2001 From: kresko Date: Mon, 10 Aug 2026 19:26:26 +0200 Subject: [PATCH 17/20] Updated cd yml file. --- .github/workflows/cd.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 22aa946bf18..3622112e4a8 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -19,4 +19,15 @@ jobs: go-version: "1.26.0" - name: Build - run: ./scripts/buildprod.sh \ No newline at end of file + run: ./scripts/buildprod.sh + + - name: Auth with GCP + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + + - name: Build and push Docker image + run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-505018/notely-ar-repo/notely:latest . \ No newline at end of file From 9b09fed433e214dd8c85268a7b589c10997c606d Mon Sep 17 00:00:00 2001 From: kresko Date: Mon, 10 Aug 2026 19:34:35 +0200 Subject: [PATCH 18/20] Updated cd yml file. --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3622112e4a8..ba47209f3ba 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -30,4 +30,4 @@ jobs: uses: google-github-actions/setup-gcloud@v2 - name: Build and push Docker image - run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-505018/notely-ar-repo/notely:latest . \ No newline at end of file + run: gcloud builds submit --tag us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest . \ No newline at end of file From 5fe1908b6c6515d855d63602150e374d728dad81 Mon Sep 17 00:00:00 2001 From: kresko Date: Mon, 10 Aug 2026 19:52:53 +0200 Subject: [PATCH 19/20] Add Cloud Run deploy step and update homepage welcome text Deploys the latest built image to Cloud Run with unauthenticated access enabled, and tweaks the index.html h1 copy. Co-Authored-By: Claude Sonnet 5 --- .github/workflows/cd.yml | 5 ++++- static/index.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ba47209f3ba..847d748456d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -30,4 +30,7 @@ jobs: uses: google-github-actions/setup-gcloud@v2 - name: Build and push Docker image - run: gcloud builds submit --tag us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest . \ No newline at end of file + run: gcloud builds submit --tag us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest . + + - name: Deploy to Cloud Run + run: gcloud run deploy notely --image us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project pure-phalanx-505018-q3 --max-instances=4 \ No newline at end of file diff --git a/static/index.html b/static/index.html index 72be101028c..5d4ad73c095 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ -

Notely

+

Welcome to Notely

From a09dfff42af4864c481c4c9ff03cb3ac86b57248 Mon Sep 17 00:00:00 2001 From: kresko Date: Mon, 10 Aug 2026 21:32:52 +0200 Subject: [PATCH 20/20] Updated cd yml file. --- .github/workflows/cd.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 847d748456d..b3e86c50ecc 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -9,6 +9,9 @@ jobs: name: Deploy runs-on: ubuntu-latest + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + steps: - name: Check out code uses: actions/checkout@v6 @@ -18,6 +21,9 @@ jobs: with: go-version: "1.26.0" + - name: Install goose + run: go install github.com/pressly/goose/v3/cmd/goose@latest + - name: Build run: ./scripts/buildprod.sh @@ -32,5 +38,8 @@ jobs: - name: Build and push Docker image run: gcloud builds submit --tag us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest . + - name: Run migrations + run: ./scripts/migrateup.sh + - name: Deploy to Cloud Run - run: gcloud run deploy notely --image us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project pure-phalanx-505018-q3 --max-instances=4 \ No newline at end of file + run: gcloud run deploy notely --image us-central1-docker.pkg.dev/pure-phalanx-505018-q3/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project pure-phalanx-505018-q3 --max-instances=4