Compare commits

...

3 Commits

Author SHA1 Message Date
Lizzy Hunt 625e4b570b
add continuous deployment step
continuous-integration/drone/push Build is failing Details
2024-04-01 17:40:37 -06:00
Lizzy Hunt 1fd1444f97
make name type content unique in dns records 2024-04-01 17:35:10 -06:00
Lizzy Hunt 38110bb19d
add cache control to static server 2024-04-01 17:34:14 -06:00
4 changed files with 35 additions and 2 deletions

View File

@ -16,6 +16,14 @@ steps:
tags: tags:
- latest - latest
- main - main
- name: continuous deployment
image: alpine:latest
commands:
- apk add -y openssh
- sh deploy.sh
environment:
SSH_KEY:
from_secret: SSH_KEY
trigger: trigger:
branch: branch:
- main - main

View File

@ -66,11 +66,19 @@ func IdContinuation(context *RequestContext, req *http.Request, resp http.Respon
} }
} }
func CacheControlMiddleware(next http.Handler, maxAge int) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
header := fmt.Sprintf("public, max-age=%d", maxAge)
w.Header().Set("Cache-Control", header)
next.ServeHTTP(w, r)
})
}
func MakeServer(argv *args.Arguments, dbConn *sql.DB) *http.Server { func MakeServer(argv *args.Arguments, dbConn *sql.DB) *http.Server {
mux := http.NewServeMux() mux := http.NewServeMux()
fileServer := http.FileServer(http.Dir(argv.StaticPath)) fileServer := http.FileServer(http.Dir(argv.StaticPath))
mux.Handle("GET /static/", http.StripPrefix("/static/", fileServer)) mux.Handle("/static/", http.StripPrefix("/static/", CacheControlMiddleware(fileServer, 3600)))
makeRequestContext := func() *RequestContext { makeRequestContext := func() *RequestContext {
return &RequestContext{ return &RequestContext{

View File

@ -59,10 +59,17 @@ func MigrateDNSRecords(dbConn *sql.DB) (*sql.DB, error) {
ttl INTEGER NOT NULL, ttl INTEGER NOT NULL,
internal BOOLEAN NOT NULL, internal BOOLEAN NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE);`) FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);`)
if err != nil { if err != nil {
return dbConn, err return dbConn, err
} }
_, err = dbConn.Exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_dns_records_name_content_type ON dns_records (name, type, content);`)
if err != nil {
return dbConn, err
}
return dbConn, nil return dbConn, nil
} }

10
deploy.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
set -e
echo $SSH_KEY | base64 -d >> /tmp/key
chmod -R 0600 /tmp/key
ssh -i /tmp/key -o StrictHostKeyChecking=no root@hatecomputers.club "systemctl restart docker-compose@hatecomputers-club"
rm /tmp/key