Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevOps improvement #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.22-alpine3.19 AS build

WORKDIR /usr/src

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .

RUN go build -o /app /usr/src/cmd/app/main.go


FROM alpine:3.19
COPY . .
COPY --from=build /app /cmd/app/exec
EXPOSE 3000
CMD ["/cmd/app/exec"]
32 changes: 19 additions & 13 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ type Config struct {
}

func NewConfig(envpaths ...string) *Config {
err := dotenv.Load(envpaths...)
if err != nil {
log.Fatal("Error loading .env file")
}
_ = dotenv.Load(envpaths...)

return &Config{
GitHubAccessToken: os.Getenv("GITHUB_ACCESS_TOKEN"),
RepoAPI: os.Getenv("REPO_API"),
GASAPI: os.Getenv("GAS_API"),
SMTPFrom: os.Getenv("SMTP_FROM"),
SMTPPass: os.Getenv("SMTP_PASS"),
SMTPHost: os.Getenv("SMTP_HOST"),
SMTPPort: os.Getenv("SMTP_PORT"),
GEMINI_API_KEY: os.Getenv("GEMINI_API_KEY"),
ADMIN_MAIL: os.Getenv("ADMIN_MAIL"),
GitHubAccessToken: readEnvOrPanic("GITHUB_ACCESS_TOKEN"),
RepoAPI: readEnvOrPanic("REPO_API"),
GASAPI: readEnvOrPanic("GAS_API"),
SMTPFrom: readEnvOrPanic("SMTP_FROM"),
SMTPPass: readEnvOrPanic("SMTP_PASS"),
SMTPHost: readEnvOrPanic("SMTP_HOST"),
SMTPPort: readEnvOrPanic("SMTP_PORT"),
GEMINI_API_KEY: readEnvOrPanic("GEMINI_API_KEY"),
ADMIN_MAIL: readEnvOrPanic("ADMIN_MAIL"),
}

}

func readEnvOrPanic(key string) string {
value := os.Getenv(key)
if value == "" {
log.Panicf("Environment variable %s is not set", key)
}
return value
}