diff --git a/.drone.yml b/.drone.yml index 2085f93..dd9ef4a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -16,7 +16,8 @@ steps: password: from_secret: docker_password repo: dutchellie/proper-website-2 - target: staging + build_args: + - APIURL=https://api.nicecock.eu/api/testingcomment tags: - dev - ${DRONE_COMMIT_SHA:0:8} @@ -63,7 +64,8 @@ steps: password: from_secret: docker_password repo: dutchellie/proper-website-2 - target: production + build_args: + - APIURL=https://api.nicecock.eu/api/comment tags: - latest - ${DRONE_COMMIT_SHA:0:8} diff --git a/Dockerfile b/Dockerfile index b584b00..743ce8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ FROM golang:1.17.8-alpine AS builder +ARG APIURL WORKDIR /project ADD . /project/ RUN go mod tidy -RUN GOARCH=wasm GOOS=js go build -o web/app.wasm -RUN go build -o app +RUN GOARCH=wasm GOOS=js go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=$APIURL'" -o web/app.wasm +RUN go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=$APIURL'" -o app FROM alpine:latest AS staging RUN apk --no-cache add ca-certificates @@ -12,13 +13,4 @@ COPY --from=builder /project/web ./web/ COPY --from=builder /project/app ./ EXPOSE 8000 ENV TESTING true -CMD ["./app"] - -FROM alpine:latest AS production -RUN apk --no-cache add ca-certificates -WORKDIR /root/ -COPY --from=builder /project/web ./web/ -COPY --from=builder /project/app ./ -EXPOSE 8000 -ENV TESTING false CMD ["./app"] \ No newline at end of file diff --git a/Makefile b/Makefile index 2b008c6..a300193 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,16 @@ +APIURL_prod := https://api.nicecock.eu/api/comment +APIURL_staging := https://api.nicecock.eu/api/testingcomment + build: - GOARCH=wasm GOOS=js go build -o web/app.wasm - go build -o app + GOARCH=wasm GOOS=js go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=${APIURL_staging}'" -o web/app.wasm + go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=${APIURL_staging}'" -o app + +build-prod: + GOARCH=wasm GOOS=js go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=${APIURL_prod}'" -o web/app.wasm + go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=${APIURL_prod}'" -o app run: build + ./app + +run-prod: build-prod ./app \ No newline at end of file diff --git a/components/guestbookpanel.go b/components/guestbookpanel.go index 136f5c3..d08b88c 100644 --- a/components/guestbookpanel.go +++ b/components/guestbookpanel.go @@ -4,7 +4,6 @@ import ( "encoding/json" "io" "net/http" - "os" "time" "dutchellie.nl/DutchEllie/proper-website-2/entity" @@ -47,10 +46,7 @@ func (g *guestbookPanel) Render() app.UI { func (g *guestbookPanel) LoadComments() { // TODO: maybe you can put this in a localbrowser storage? - url := apiurl + "api/comment" - if os.Getenv("TESTING") == "true" { - url = apiurl + "api/testingcomment" - } + url := ApiURL res, err := http.Get(url) if err != nil { app.Log(err) diff --git a/components/homepage.go b/components/homepage.go index 2fc03b7..f6f6aea 100644 --- a/components/homepage.go +++ b/components/homepage.go @@ -5,14 +5,13 @@ import ( "encoding/json" "fmt" "net/http" - "os" "dutchellie.nl/DutchEllie/proper-website-2/entity" "github.com/maxence-charriere/go-app/v9/pkg/app" ) -const ( - apiurl = "https://api.nicecock.eu/" +var ( + ApiURL string ) type Homepage struct { @@ -48,10 +47,7 @@ func (p *Homepage) Render() app.UI { fmt.Printf("err: %v\n", err) return } - url := apiurl + "api/comment" - if os.Getenv("TESTING") == "true" { - url = apiurl + "api/testingcomment" - } + url := ApiURL req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata)) if err != nil {