Add environment variable and build script for production deployment
Some checks failed
Actions Build Docker Image / Build-Binary (push) Failing after 4s
Actions Build Docker Image / Build-Docker-Image (push) Successful in 9s

This commit is contained in:
Alex Borisov 2024-02-01 19:58:00 +03:00
parent 0078d4551b
commit 913843ff3b
3 changed files with 11 additions and 5 deletions

View File

@ -58,6 +58,8 @@ jobs:
- name: Build Binary
run: |
go build -o current_date/$(basename ${{ gitea.repository }}) .
env:
ENVIRONMENT: production
- name: Upload binary to soaska.ru
run: |
package_name=$(basename ${{ gitea.repository }})

View File

@ -6,6 +6,8 @@ COPY go.mod go.sum /app/
RUN go mod download
COPY *.go /app/
ENV ENVIRONMENT=production
RUN go build -o main .
# Stage 2: Use a slim image for the runnable container
FROM alpine as runtime

8
run.go
View File

@ -86,9 +86,11 @@ func main() {
}
func getEnv() (string, string, string, string, string) {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
if os.Getenv("ENVIRONMENT") != "production" {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
// Get environment variables