Skip to content

Updated readme #1390

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 30 commits into
base: main
Choose a base branch
from
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
ceb2cb8
Updated readme
WilliamBadgett97 Apr 12, 2025
bfe0459
added ci
WilliamBadgett97 Apr 12, 2025
69f5005
updated ci test
WilliamBadgett97 Apr 12, 2025
25a1add
added apikey test
WilliamBadgett97 Apr 12, 2025
96c705a
update ci test
WilliamBadgett97 Apr 12, 2025
21b694c
updated test code
WilliamBadgett97 Apr 12, 2025
a92e061
Added coverage
WilliamBadgett97 Apr 12, 2025
5fd0154
added test badge
WilliamBadgett97 Apr 12, 2025
26f7860
Added fmt job
WilliamBadgett97 Apr 12, 2025
cf51a70
updated ci jobs
WilliamBadgett97 Apr 12, 2025
6fc18f4
added staticcheck
WilliamBadgett97 Apr 12, 2025
cc639ab
Remove unused function
WilliamBadgett97 Apr 12, 2025
df968c9
Remove unused function
WilliamBadgett97 Apr 12, 2025
ecf6d44
formatted
WilliamBadgett97 Apr 12, 2025
491e46f
added gosec security checking
WilliamBadgett97 Apr 13, 2025
19a6d25
.
WilliamBadgett97 Apr 13, 2025
120851c
Run gosec
WilliamBadgett97 Apr 13, 2025
586e6b0
Fixed gosec issues
WilliamBadgett97 Apr 13, 2025
775ecf9
formatted
WilliamBadgett97 Apr 13, 2025
3af10d4
added cd
WilliamBadgett97 Apr 13, 2025
9728216
formatting
WilliamBadgett97 Apr 13, 2025
0eeeaef
Removed unneeded comments
WilliamBadgett97 Apr 13, 2025
e53ef47
fixed cd
WilliamBadgett97 Apr 13, 2025
29c8334
Updated go version in cd
WilliamBadgett97 Apr 13, 2025
f42af56
updated CD job name
WilliamBadgett97 Apr 13, 2025
75be89a
cd updates
WilliamBadgett97 Apr 14, 2025
1107c0d
updated cd process
WilliamBadgett97 Apr 14, 2025
b83aae6
updated cd
WilliamBadgett97 Apr 14, 2025
856af00
updates
WilliamBadgett97 Apr 14, 2025
feb8bb7
updated cd
WilliamBadgett97 Apr 14, 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
46 changes: 46 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: cd
on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Set up go
uses: actions/setup-go@v2
with:
go-version: '1.22'

- name: Check out repository
uses: actions/checkout@v2

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

- name: Build
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/notely-456712/notely-ar-repo/my-image:1.0.0 .

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-456712/notely-ar-repo/my-image:1.0.0 --region us-central1

- name: Run migration
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: ./scripts/migrateup.sh
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 Tests
run: go test ./internal/auth -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: Check Formatting
run: test -z $(go fmt ./...)

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
8 changes: 6 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/WilliamBadgett97/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,8 @@ 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!
Williams's version of Boot.dev's Notely app.
5 changes: 5 additions & 0 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"errors"
"fmt"
"net/http"
"strings"
)
Expand All @@ -15,6 +16,10 @@ func GetAPIKey(headers http.Header) (string, error) {
return "", ErrNoAuthHeaderIncluded
}
splitAuth := strings.Split(authHeader, " ")
fmt.Println("SPLIT AUTH")
fmt.Println(splitAuth)
fmt.Println(len(splitAuth))
fmt.Println(len(splitAuth[0]))
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {
return "", errors.New("malformed authorization header")
}
Expand Down
33 changes: 33 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package auth

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

func TestGetApiKey(t *testing.T) {
var headerTestOne = http.Header{
"Authorization": []string{"ApiKey 12345-abcde-67890-fghij"},
}
var headerTestTwo = http.Header{
"Authorization": []string{"ApiKey "},
}
type test struct {
input http.Header
want string
}
tests := []test{
{input: headerTestOne, want: "12345-abcde-67890-fghij"},
{input: headerTestTwo, want: ""},
}
for _, tc := range tests {
got, err := GetAPIKey(tc.input)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(tc.want, got) {
t.Fatalf("expected: %v, got: %v", tc.want, got)
}
}
}
7 changes: 6 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ 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 data %s", err)
w.WriteHeader(500)
return
}
}
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: time.Second * 5,
}

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