Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2bae508
Add project attribution to README
gerrithbrink Jul 26, 2026
3fedb49
Merge pull request #1 from gerrithbrink/addtests
gerrithbrink Jul 26, 2026
2bc6495
Update README.md
gerrithbrink Jul 26, 2026
8b2a3ca
Add CI workflow configuration
gerrithbrink Jul 26, 2026
7d16552
Merge pull request #2 from gerrithbrink/addtests
gerrithbrink Jul 26, 2026
7617796
Revert "Add project attribution to README"
gerrithbrink Jul 26, 2026
85d86f9
Add personal identifier to README
gerrithbrink Jul 26, 2026
ec87f3f
Add CI workflow with Go testing pipeline
gerrithbrink Jul 26, 2026
e86bd46
Replace forced failure with Go version check in CI
gerrithbrink Jul 26, 2026
0490b18
Merge branch 'main' into addtests
gerrithbrink Jul 26, 2026
6df2a5c
Add unit tests for GetAPIKey and update CI workflow
gerrithbrink Jul 26, 2026
8cd13d8
Fix syntax error in CI unit test step
gerrithbrink Jul 26, 2026
474c4df
Enable test coverage in CI pipeline
gerrithbrink Jul 26, 2026
8867e41
Add CI build status badge to README
gerrithbrink Jul 26, 2026
8368636
Update test badge URL in README
gerrithbrink Jul 26, 2026
107a515
Update CI badge workflow path
gerrithbrink Jul 26, 2026
768e1d3
Fix broken CI badge URL in README
gerrithbrink Jul 26, 2026
51762f5
Add formatting checks to CI pipeline
gerrithbrink Jul 26, 2026
c0dcf5c
Add staticcheck to CI pipeline
gerrithbrink Jul 26, 2026
18fd3da
Remove unused function
gerrithbrink Jul 26, 2026
c93dad8
Remove redundant newline in main.go
gerrithbrink Jul 26, 2026
68db60c
Fix CI staticcheck path and add whitespace to main.go
gerrithbrink Jul 26, 2026
3ffd98d
Update ci.yml
gerrithbrink Jul 26, 2026
51b3dd0
Update CI workflow to use setup-go and manual staticcheck installation
gerrithbrink Jul 26, 2026
4dd2b69
Add gosec to CI workflow
gerrithbrink Jul 26, 2026
24cf94a
Add security test step to CI pipeline
gerrithbrink Jul 26, 2026
dcb2f6b
Improve server response handling and logging
gerrithbrink Jul 26, 2026
e398ffe
Fix JSON response double write and add server timeout
gerrithbrink Jul 26, 2026
6dd9c60
Update gosec command in CI workflow
gerrithbrink Jul 26, 2026
b96f37f
Create cd.yml
gerrithbrink Jul 26, 2026
2fcbe8b
Update CD workflow step name to Deploy
gerrithbrink Jul 26, 2026
c3686eb
Configure GCP authentication and image build in CD pipeline
gerrithbrink Jul 28, 2026
860561d
Add Cloud Run deployment step to CD workflow
gerrithbrink Jul 28, 2026
9be5957
Update landing page heading
gerrithbrink Jul 28, 2026
54277e1
Add database migration step to CD pipeline
gerrithbrink Jul 28, 2026
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
1 change: 1 addition & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
!notely
google-cloud-sdk
48 changes: 48 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: cd

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}

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: Install Goose
run: go install github.com/pressly/goose/v3/cmd/goose@latest

- name: Deploy
run: ./scripts/buildprod.sh

- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v3'

- name: 'Use gcloud CLI'
run: 'gcloud info'

- name: 'Build Docker Image'
run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-503820/notely-ar-repo/notely:latest

- name: Migrate
run: ./scripts/migrateup.sh

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-503820/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project notely-503820 --max-instances=4
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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: Unit Tests
run: go test -cover ./...

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Security Test
run: gosec ./...



style:
name: Style
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.25.1"

- name: Check formatting
run: test -z $(go fmt ./...)

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ out
.env
learn-cicd-starter
notely
google-cloud-sdk
notely-503820-0b56b0c8c032.json
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![Test Badge](https://github.com/gerrithbrink/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).
Expand All @@ -21,3 +22,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's version of Boot.dev's Notely app.
88 changes: 88 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package auth

import (
"errors"
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
headers http.Header
wantKey string
wantErr error
wantErrText string
}{
{
name: "Missing Authorization header",
headers: http.Header{},
wantKey: "",
wantErr: ErrNoAuthHeaderIncluded,
},
{
name: "Empty Authorization header value",
headers: http.Header{
"Authorization": []string{""},
},
wantKey: "",
wantErr: ErrNoAuthHeaderIncluded,
},
{
name: "Malformed header - missing ApiKey prefix",
headers: http.Header{
"Authorization": []string{"Bearer 12345"},
},
wantKey: "",
wantErrText: "malformed authorization header",
},
{
name: "Malformed header - missing key component",
headers: http.Header{
"Authorization": []string{"ApiKey"},
},
wantKey: "",
wantErrText: "malformed authorization header",
},
{
name: "Malformed header - invalid prefix casing",
headers: http.Header{
"Authorization": []string{"apikey 12345"},
},
wantKey: "",
wantErrText: "malformed authorization header",
},
{
name: "Valid Authorization header",
headers: http.Header{
"Authorization": []string{"ApiKey my-secret-api-key-123"},
},
wantKey: "my-secret-api-key-123",
wantErr: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotKey, err := GetAPIKey(tt.headers)

// Check error expectations
if tt.wantErr != nil {
if !errors.Is(err, tt.wantErr) {
t.Errorf("GetAPIKey() error = %v, wantErr %v", err, tt.wantErr)
}
} else if tt.wantErrText != "" {
if err == nil || err.Error() != tt.wantErrText {
t.Errorf("GetAPIKey() error = %v, wantErrText %q", err, tt.wantErrText)
}
} else if err != nil {
t.Errorf("GetAPIKey() unexpected error = %v", err)
}

// Check key expectation
if gotKey != tt.wantKey {
t.Errorf("GetAPIKey() gotKey = %q, want %q", gotKey, tt.wantKey)
}
})
}
}
5 changes: 4 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
return
}
w.WriteHeader(code)
w.Write(dat)
_, err = w.Write(dat)
if err != nil {
log.Printf("Failed to write response: %v", err)
}
}
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"net/http"
"os"
"strings"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -89,10 +91,13 @@ 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)
cleanPort := strings.ReplaceAll(strings.ReplaceAll(port, "\n", ""), "\r", "")

log.Printf("Serving on port: %s\n", cleanPort)
log.Fatal(srv.ListenAndServe())
}
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body class="section">
<h1>Notely</h1>
<h1>Welcome to Notely</h1>

<div id="userCreationContainer" class="section">
<input id="nameField" type="text" placeholder="Enter your name">
Expand Down