diff --git a/.drone.yml b/.drone.yml index 5837a28..72c6f2d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -16,8 +16,6 @@ steps: password: from_secret: docker_password repo: dutchellie/proper-website-2 - build_args: - - APIURL=https://api.quenten.nl/api/testing tags: - dev - ${DRONE_COMMIT_SHA:0:8} @@ -64,8 +62,6 @@ steps: password: from_secret: docker_password repo: dutchellie/proper-website-2 - build_args: - - APIURL=https://api.quenten.nl/api tags: - latest - ${DRONE_COMMIT_SHA:0:8} diff --git a/.drone/helm/chart/templates/deployment.yaml b/.drone/helm/chart/templates/deployment.yaml index 227fed4..243bffe 100644 --- a/.drone/helm/chart/templates/deployment.yaml +++ b/.drone/helm/chart/templates/deployment.yaml @@ -31,5 +31,9 @@ spec: ports: - name: http containerPort: 8000 + {{- if .Values.containerEnv }} + env: {{ toYaml .Values.containerEnv | nindent 12 }} + {{- end }} + \ No newline at end of file diff --git a/.drone/helm/chart/values.yaml b/.drone/helm/chart/values.yaml index c9f7d2c..a7707d9 100644 --- a/.drone/helm/chart/values.yaml +++ b/.drone/helm/chart/values.yaml @@ -6,6 +6,7 @@ podAnnotations: {} containerName: newsite image: dutchellie/proper-website-2:latest imagePullPolicy: Always +containerEnv: [] service: name: newsite-service diff --git a/.drone/helm/prod-val.yaml b/.drone/helm/prod-val.yaml index c1a0fd9..43ae903 100644 --- a/.drone/helm/prod-val.yaml +++ b/.drone/helm/prod-val.yaml @@ -1,4 +1,7 @@ name: newsite-prod +containerEnv: + - name: APIURL + value: https://api.quenten.nl/api service: name: newsite-prod ingress: diff --git a/.drone/helm/staging-val.yaml b/.drone/helm/staging-val.yaml index 59551d0..b464915 100644 --- a/.drone/helm/staging-val.yaml +++ b/.drone/helm/staging-val.yaml @@ -1,4 +1,7 @@ name: newsite-staging +containerEnv: + - name: APIURL + value: https://api.quenten.nl/api/testing service: name: newsite-staging ingress: diff --git a/Dockerfile b/Dockerfile index 9f9281a..b0f1dde 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,8 @@ ARG APIURL WORKDIR /project ADD . /project/ RUN go mod tidy -RUN GOARCH=wasm GOOS=js go build -o web/app.wasm -ldflags="-X 'main.ApiURL=$APIURL'" ./src -RUN go build -o app -ldflags="-X 'main.ApiURL=$APIURL'" ./src +RUN GOARCH=wasm GOOS=js go build -o web/app.wasm ./src +RUN go build -o app ./src FROM alpine:latest AS staging RUN apk --no-cache add ca-certificates diff --git a/src/homepage.go b/src/homepage.go index bbba6f7..b08e0c0 100644 --- a/src/homepage.go +++ b/src/homepage.go @@ -10,10 +10,6 @@ import ( "github.com/maxence-charriere/go-app/v9/pkg/app" ) -var ( - ApiURL string -) - type Homepage struct { app.Compo } diff --git a/src/main.go b/src/main.go index 8f0c704..194639f 100644 --- a/src/main.go +++ b/src/main.go @@ -4,6 +4,7 @@ import ( "compress/gzip" "log" "net/http" + "os" "github.com/gorilla/handlers" "github.com/maxence-charriere/go-app/v9/pkg/app" @@ -15,7 +16,15 @@ import ( // collection *mongo.Collection //} +var ( + ApiURL string +) + func main() { + ApiURL = os.Getenv("APIURL") + if ApiURL == "" { + log.Fatalln("Unable to get API URL from environment variables!") + } homepage := NewHomepage() aboutpage := NewAboutPage() galaxiespage := NewGalaxiesPage()