Skip to content

Test #1489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

Test #1489

Show file tree
Hide file tree
Changes from all commits
Commits
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
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@v4

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

- name: Set up Goose
uses: mscno/setup-goose@v1

- name: Build script
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"

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

- name: "Build docker image"
run: "gcloud builds submit --tag us-central1-docker.pkg.dev/notely-459220/notely-ar-repo/notely:latest . "

- name: "Run Goose migration"
run: scripts/migrateup.sh

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

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

- name: Run gosec tests
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: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

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

- name: Check linting
run: staticcheck ./...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 debian:stable-slim
FROM debian:stable-slim

RUN apt-get update && apt-get install -y ca-certificates

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![alt text goes here](https://github.com/Benjysparks/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 @@ -18,6 +20,7 @@ Run the server:
go build -o notely && ./notely
```

*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.
_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!
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!
Benjys version of boot.dev's Notely app
25 changes: 25 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package auth

import (
"net/http"
"testing"
)

func TestAPI(t *testing.T) {

testKey := "ThisIsAKey"

header := http.Header{}
header.Add("Content-Type", "application/json")
header.Set("Authorization", "ApiKey "+testKey)

key, err := GetAPIKey(header)
if err != nil {
t.Fatalf("error: could not get api key: %v", err)
}
if key == "ThisIsAKey" {
return
} else {
t.Fatalf("error: expected %v, got %v, : %v", testKey, 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.Printf("Error writing response: %v", err)

}
}
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package main
import (
"database/sql"
"embed"
"github.com/go-chi/chi"
"github.com/go-chi/cors"
"github.com/joho/godotenv"
"io"
"log"
"net/http"
"os"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
"github.com/joho/godotenv"
"time"

"github.com/bootdotdev/learn-cicd-starter/internal/database"

Expand Down Expand Up @@ -88,9 +88,11 @@ func main() {
v1Router.Get("/healthz", handlerReadiness)

router.Mount("/v1", v1Router)
timeDur, _ := time.ParseDuration("10s")
srv := &http.Server{
Addr: ":" + port,
Handler: router,
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: timeDur,
}

log.Printf("Serving on port: %s\n", port)
Expand Down
Loading