Testing and normal API
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

This commit is contained in:
DutchEllie 2022-03-13 20:18:07 +01:00
parent 3ade18b568
commit af1cd54cd4
Signed by: DutchEllie
SSH Key Fingerprint: SHA256:dKq6ZSgN5E3Viqrw/+xAdf2VdR6hdRGNyrYqXXwfjTY
5 changed files with 23 additions and 27 deletions

View File

@ -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}

View File

@ -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"]

View File

@ -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

View File

@ -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)

View File

@ -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 {