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

Change Fatal termination to Error. File .env not indispensable. #6

Open
wants to merge 3 commits into
base: master
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
26 changes: 14 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
FROM golang:1.14-buster
FROM golang:1.14-buster AS build

RUN go version
ENV GOPATH=/
WORKDIR /src/
COPY ./ /src/

COPY ./ ./
# build go app
RUN go mod download; CGO_ENABLED=0 go build -o /todo-app ./cmd/main.go

# install psql
RUN apt-get update
RUN apt-get -y install postgresql-client

# make wait-for-postgres.sh executable
RUN chmod +x wait-for-postgres.sh
FROM alpine:latest

# build go app
RUN go mod download
RUN go build -o todo-app ./cmd/main.go
# copy go app, config and wait-for-postgres.sh
COPY --from=build /todo-app /todo-app
COPY ./configs/ /configs/
COPY ./wait-for-postgres.sh ./

# install psql and make wait-for-postgres.sh executable
RUN apk --no-cache add postgresql-client && chmod +x wait-for-postgres.sh

CMD ["./todo-app"]
CMD ["/todo-app"]
6 changes: 5 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func main() {
}

if err := godotenv.Load(); err != nil {
logrus.Fatalf("error loading env variables: %s", err.Error())
logrus.Errorf("error loading env variables: %s", err.Error())
}

if "" == os.Getenv("DB_PASSWORD") {
logrus.Fatalf("error cannot initializing database password")
}

db, err := repository.NewPostgresDB(repository.Config{
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
todo-app:
build: ./
command: ./wait-for-postgres.sh db ./todo-app
command: sh -c "./wait-for-postgres.sh db; /todo-app"
ports:
- 8000:8000
depends_on:
Expand Down