Testing and normal API
This commit is contained in:
		
							parent
							
								
									6d3a99c63c
								
							
						
					
					
						commit
						face13b207
					
				@ -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}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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"]  
 | 
			
		||||
							
								
								
									
										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:
 | 
			
		||||
	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
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user