Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrose14 committed Nov 25, 2023
1 parent 0dc9084 commit fc0a414
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
14 changes: 4 additions & 10 deletions cmd/webapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ func init() {

func main() {
certsDir := flag.String("certs", "certs", "Directory to store letsencrypt certs")
daemonize := flag.Bool("d", false, "Whether to daemonize on start")
dbfile := flag.String("db", "store.sqlite", "sqlite database file")
host := flag.String("host", "", "optional hostname for webserver")
host := flag.String("host", "", "Optional hostname for webserver")
pidfile := flag.String("pidfile", "", "Optional file to write process ID to")
secretsFile := flag.String("secrets", "config/secrets.yaml", "Path to local secrets file")
flag.Parse()
Expand Down Expand Up @@ -81,8 +80,6 @@ func main() {
log.Fatalf("failed to parse secrets: %s", err)
}

log.Printf("hello, world! v1")

db, err := sql.Open("sqlite3", "file:"+*dbfile+"?cache=shared")
if err != nil {
log.Fatalf("failed to open sqlite connection: %s", err)
Expand All @@ -97,10 +94,6 @@ func main() {
log.Fatalf("failed to upsert database tables: %s", err)
}

if *daemonize {

}

if *pidfile != "" {
if err := ioutil.WriteFile(*pidfile, []byte(strconv.Itoa(os.Getpid())), 0666); err != nil {
log.Fatalf("failed to write pidfile: %+v", err)
Expand Down Expand Up @@ -153,6 +146,7 @@ func main() {
// TODO: in a handler wrapper, redirect http to https (in production only)

if !inDev {
log.Printf("starting autocert manager")
if err := os.MkdirAll(*certsDir, 0777); err != nil {
log.Fatalf("failed to create certs dir: %s", err)
}
Expand All @@ -162,8 +156,8 @@ func main() {
Prompt: autocert.AcceptTOS,
Email: "[email protected]",
HostPolicy: func(ctx context.Context, host string) error {
log.Printf("autocert query for host %q", host)
return autocert.HostWhitelist("solarsnoop.com", "www.solarsnoop.com")(ctx, host)
log.Printf("autocert query for host %q, responding with %v", host, []string{svr.host, "www." + svr.host})
return autocert.HostWhitelist(svr.host, "www."+svr.host)(ctx, host)
},
Cache: autocert.DirCache(*certsDir),
}
Expand Down
7 changes: 3 additions & 4 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ set -e
# Run on initial instance creation:
# > sudo apt-get update
# > sudo apt-get install podman
# > sudo setcap cap_net_bind_service=+ep /usr/bin/podman
# > sudo setcap cap_net_bind_service=+ep $(which slirp4netns)

make webapp-linux

HOST_IP=$(gcloud compute --project ian-rose instances describe instance-1 --zone us-central1-a --format "get(networkInterfaces[0].accessConfigs.natIP)")

#docker buildx build --platform linux/amd64 --build-arg BIN=bin/linux_amd64/webapp -t us-central1-docker.pkg.dev/ian-rose/docker-1/webapp:latest .
#docker build -t us-central1-docker.pkg.dev/ian-rose/docker-1/webapp:latest .
#docker push us-central1-docker.pkg.dev/ian-rose/docker-1/webapp:latest

gcloud compute --project ian-rose ssh ianrose14@instance-1 --zone us-central1-a -- mkdir -p config/
gcloud compute --project ian-rose scp --zone us-central1-a config/* ianrose14@instance-1:config/
gcloud compute --project ian-rose scp --zone us-central1-a scripts/startup.sh ianrose14@instance-1:

ssh ianrose14@"${HOST_IP}" bash ./startup.sh
gcloud compute --project ian-rose ssh ianrose14@instance-1 --zone us-central1-a -- bash ./startup.sh
7 changes: 7 additions & 0 deletions scripts/login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

gcloud auth login [email protected]
gcloud config set project ian-rose
gcloud config list
2 changes: 1 addition & 1 deletion scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ mkdir -p data
# ref 2: https://github.com/containers/podman/issues/13691#issuecomment-1081913637
gcloud auth --quiet print-access-token | podman login -u oauth2accesstoken --password-stdin us-central1-docker.pkg.dev
podman pull us-central1-docker.pkg.dev/ian-rose/docker-1/webapp:latest
podman run -d -p 8080:80 -p 8443:443 --restart=no \
podman run -d -p 80:80 -p 443:443 --restart=no \
-v "$(pwd)/config":/root/config/ -v "$(pwd)/data":/root/data/ --name webapp \
us-central1-docker.pkg.dev/ian-rose/docker-1/webapp:latest /root/webapp -host ianthomasrose.com

0 comments on commit fc0a414

Please sign in to comment.