Testing and normal API
This commit is contained in:
parent
3ade18b568
commit
af1cd54cd4
@ -16,7 +16,8 @@ steps:
|
|||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
repo: dutchellie/proper-website-2
|
repo: dutchellie/proper-website-2
|
||||||
target: staging
|
build_args:
|
||||||
|
- APIURL=https://api.nicecock.eu/api/testingcomment
|
||||||
tags:
|
tags:
|
||||||
- dev
|
- dev
|
||||||
- ${DRONE_COMMIT_SHA:0:8}
|
- ${DRONE_COMMIT_SHA:0:8}
|
||||||
@ -63,7 +64,8 @@ steps:
|
|||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
repo: dutchellie/proper-website-2
|
repo: dutchellie/proper-website-2
|
||||||
target: production
|
build_args:
|
||||||
|
- APIURL=https://api.nicecock.eu/api/comment
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${DRONE_COMMIT_SHA:0:8}
|
- ${DRONE_COMMIT_SHA:0:8}
|
||||||
|
14
Dockerfile
14
Dockerfile
@ -1,9 +1,10 @@
|
|||||||
FROM golang:1.17.8-alpine AS builder
|
FROM golang:1.17.8-alpine AS builder
|
||||||
|
ARG APIURL
|
||||||
WORKDIR /project
|
WORKDIR /project
|
||||||
ADD . /project/
|
ADD . /project/
|
||||||
RUN go mod tidy
|
RUN go mod tidy
|
||||||
RUN GOARCH=wasm GOOS=js go build -o web/app.wasm
|
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 -o app
|
RUN go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=$APIURL'" -o app
|
||||||
|
|
||||||
FROM alpine:latest AS staging
|
FROM alpine:latest AS staging
|
||||||
RUN apk --no-cache add ca-certificates
|
RUN apk --no-cache add ca-certificates
|
||||||
@ -13,12 +14,3 @@ COPY --from=builder /project/app ./
|
|||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
ENV TESTING true
|
ENV TESTING true
|
||||||
CMD ["./app"]
|
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"]
|
|
14
Makefile
14
Makefile
@ -1,6 +1,16 @@
|
|||||||
|
APIURL_prod := https://api.nicecock.eu/api/comment
|
||||||
|
APIURL_staging := https://api.nicecock.eu/api/testingcomment
|
||||||
|
|
||||||
build:
|
build:
|
||||||
GOARCH=wasm GOOS=js go build -o web/app.wasm
|
GOARCH=wasm GOOS=js go build -ldflags="-X 'dutchellie.nl/DutchEllie/proper-website-2/components.ApiURL=${APIURL_staging}'" -o web/app.wasm
|
||||||
go build -o app
|
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
|
run: build
|
||||||
./app
|
./app
|
||||||
|
|
||||||
|
run-prod: build-prod
|
||||||
|
./app
|
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"dutchellie.nl/DutchEllie/proper-website-2/entity"
|
"dutchellie.nl/DutchEllie/proper-website-2/entity"
|
||||||
@ -47,10 +46,7 @@ func (g *guestbookPanel) Render() app.UI {
|
|||||||
|
|
||||||
func (g *guestbookPanel) LoadComments() {
|
func (g *guestbookPanel) LoadComments() {
|
||||||
// TODO: maybe you can put this in a localbrowser storage?
|
// TODO: maybe you can put this in a localbrowser storage?
|
||||||
url := apiurl + "api/comment"
|
url := ApiURL
|
||||||
if os.Getenv("TESTING") == "true" {
|
|
||||||
url = apiurl + "api/testingcomment"
|
|
||||||
}
|
|
||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log(err)
|
app.Log(err)
|
||||||
|
@ -5,14 +5,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
|
|
||||||
"dutchellie.nl/DutchEllie/proper-website-2/entity"
|
"dutchellie.nl/DutchEllie/proper-website-2/entity"
|
||||||
"github.com/maxence-charriere/go-app/v9/pkg/app"
|
"github.com/maxence-charriere/go-app/v9/pkg/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var (
|
||||||
apiurl = "https://api.nicecock.eu/"
|
ApiURL string
|
||||||
)
|
)
|
||||||
|
|
||||||
type Homepage struct {
|
type Homepage struct {
|
||||||
@ -48,10 +47,7 @@ func (p *Homepage) Render() app.UI {
|
|||||||
fmt.Printf("err: %v\n", err)
|
fmt.Printf("err: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
url := apiurl + "api/comment"
|
url := ApiURL
|
||||||
if os.Getenv("TESTING") == "true" {
|
|
||||||
url = apiurl + "api/testingcomment"
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata))
|
req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user