Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4e95785
changed README
epenick123 Aug 5, 2025
d1241fd
ci.yml file
epenick123 Aug 5, 2025
82952e4
run go version in ci.yml file
epenick123 Aug 5, 2025
04bf27e
added auth_test.go for testing GetAPiKey function
epenick123 Aug 6, 2025
92717fe
breaking GetApiKey function on purpose for testing, splitAuth[2]
epenick123 Aug 6, 2025
efd5b96
breaking getapikey function
epenick123 Aug 6, 2025
46fd83d
fixing broken function for test
epenick123 Aug 6, 2025
29cc675
added -cover flag to go test CI workflow
epenick123 Aug 6, 2025
3e8bdbd
fixing errors from break
epenick123 Aug 6, 2025
5b050eb
added testing badge to README
epenick123 Aug 6, 2025
2833127
updated ci.yml to add new Style formatting test
epenick123 Aug 6, 2025
dfaecc8
added style test to ci.yml
epenick123 Aug 6, 2025
7193443
add staticcheck to ci.yml in the style job
epenick123 Aug 6, 2025
05e3316
added test unused function in main and run staticcheck step to ci.yml
epenick123 Aug 6, 2025
291555c
add gosec to ci.yml
epenick123 Aug 6, 2025
7a7a4e1
moving gosec in ci.yml
epenick123 Aug 6, 2025
f22a0a9
Merge remote-tracking branch 'origin/main' into addtests
epenick123 Aug 6, 2025
fa6e493
removed unused function, fixed gosec security issues
epenick123 Aug 6, 2025
1354f23
added cd.yml and set up buildprod
epenick123 Aug 7, 2025
6c6308a
set up google cloud sdk in cd.yml
epenick123 Aug 7, 2025
ea0228b
add google cloud run to cd.yml and update index.html
epenick123 Aug 7, 2025
865b81a
changing Dockerfile and cd.yml
epenick123 Aug 7, 2025
2879c87
added goose migrations to turso database into cd.yml
epenick123 Aug 7, 2025
f735b1c
added goose migrations to turso database into cd.yml
epenick123 Aug 7, 2025
523d155
fix cd.yml, reorder steps
epenick123 Aug 8, 2025
3162b8f
fix cd.yml, reorder steps
epenick123 Aug 8, 2025
5ffc8bb
add database_url checks
epenick123 Aug 8, 2025
82311b5
fix cd.yml
epenick123 Aug 8, 2025
4b5a923
fix cd.yml and goose migrate shell script
epenick123 Aug 8, 2025
b69bf89
fix cd.yml and goose migrate shell script
epenick123 Aug 8, 2025
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
53 changes: 53 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.0"

- name: Set up Goose
run: go install github.com/pressly/goose/v3/cmd/goose@latest

- name: Build app
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@v2'
with:
version: '>= 363.0.0'

- name: Build and push Docker image
run: gcloud builds submit --tag us-central1-docker.pkg.dev/red-girder-468300-f2/notely-ar-repo/notely:latest .

- name: Debug DATABASE_URL
run: echo "DATABASE_URL starts with ${DATABASE_URL:0:20}"

- name: Check if DATABASE_URL is set
run: '[ -z "$DATABASE_URL" ] && echo "DATABASE_URL is empty" || echo "DATABASE_URL is set"'

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

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/red-girder-468300-f2/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project red-girder-468300-f2 --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@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.0"

- name: Run 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

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.0"

- name: Style
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ RUN apt-get update && apt-get install -y ca-certificates

ADD notely /usr/bin/notely

ADD static /static

CMD ["notely"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests status badge](https://github.com/epenick123/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 +23,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!

Eric's version of Boot.dev's Notely app.
24 changes: 24 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package auth

import (
"net/http"
"testing"
)

func TestCorrectAPIKey(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
req.Header.Set("Authorization", "ApiKey zesxrctfvygbunijmo78516zesxdfjnimkop")

actual_key, err := GetAPIKey(req.Header)
if actual_key != "zesxrctfvygbunijmo78516zesxdfjnimkop" || err != nil {
t.Errorf("incorrect or missing key")
}
}

func TestMissingHeader(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
actual_key, err := GetAPIKey(req.Header)
if actual_key != "" || err == nil {
t.Errorf("expected empty key and an error when header is missing, got key=%q, err=%v", actual_key, err)
}
}
6 changes: 5 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
return
}
w.WriteHeader(code)
w.Write(dat)
_, err = w.Write(dat)
if err != nil {
// Log the error or handle it appropriately
log.Printf("Error writing response: %v", err)
}
}
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -89,8 +90,9 @@ func main() {

router.Mount("/v1", v1Router)
srv := &http.Server{
Addr: ":" + port,
Handler: router,
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: 30 * time.Second,
}

log.Printf("Serving on port: %s\n", port)
Expand Down
3 changes: 1 addition & 2 deletions scripts/migrateup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ if [ -f .env ]; then
source .env
fi

cd sql/schema
goose turso $DATABASE_URL up
goose turso "$DATABASE_URL" up -dir sql/schema
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