diff --git a/Dockerfile b/Dockerfile index 8677270..76d3d13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,14 @@ ENV CGO_ENABLED=0 ENV GOOS=linux ENV GOARCH=amd64 +# Install goose +WORKDIR /goose.git + +RUN git clone https://github.com/pressly/goose.git . +RUN go build -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb' \ + -o goose ./cmd/goose + +# Build app WORKDIR /app # Copy the Go modules and dependencies @@ -20,22 +28,17 @@ COPY ./src/internal ./internal RUN go build -o main cmd/frontend/* -# --- Stage 2: Run the application --- +# --- Stage 3: Run the application --- FROM alpine:latest -ENV DB_HOST="10.99.0.3" -ENV DB_PORT="5432" -ENV DB_NAME="crowsnest" -ENV DB_USER="crow" -ENV DB_PASS="" - WORKDIR /app # Copy the built binary from the builder stage COPY --from=builder /app/main . +COPY --from=builder /goose.git/goose . COPY ./src/assets ./assets EXPOSE 8080 # Command to run the application -CMD ["/app/main"] +CMD ["sh", "-c", "/app/goose -dir=/app/assets/migrations/ postgres postgresql://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$DB_NAME up && /app/main"] diff --git a/Makefile b/Makefile index 6854d81..db1c430 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,30 @@ +DB_HOST="10.99.0.3" +DB_PORT="5432" +DB_NAME="crowsnest" +DB_USER="crow" +DB_PASS="4LlKpnQ2RZPzL13BSpkW4k" + go-run: - cd src; DB_USER=crow DB_PASS=4LlKpnQ2RZPzL13BSpkW4k DB_NAME=crowsnest DB_HOST=10.99.0.3 go run cmd/frontend/* + cd src; DB_USER=$(DB_USER) DB_PASS=$(DB_PASS) DB_NAME=$(DB_NAME) DB_HOST=$(DB_HOST) go run cmd/frontend/* + +docker-push: docker-build + docker push git.kohout-dev.de/crowsnest/crowsnest:latest docker-run: docker-build - docker run --rm -p 8080:8080 --env DB_PASS="4LlKpnQ2RZPzL13BSpkW4k" git.kohout-dev.de/crowsnest/crowsnest:latest + docker run \ + --env DB_HOST=$(DB_HOST) \ + --env DB_PORT=$(DB_PORT) \ + --env DB_NAME=$(DB_NAME) \ + --env DB_USER=$(DB_USER) \ + --env DB_PASS=$(DB_PASS) \ + --rm -p 8080:8080 git.kohout-dev.de/crowsnest/crowsnest:latest docker-build: - docker build --platform linux/amd64 -t git.kohout-dev.de/crowsnest/crowsnest:latest . \ - && docker push git.kohout-dev.de/crowsnest/crowsnest:latest + docker build \ + --build-arg DB_HOST=$(DB_HOST) \ + --build-arg DB_PORT=$(DB_PORT) \ + --build-arg DB_NAME=$(DB_NAME) \ + --build-arg DB_USER=$(DB_USER) \ + --build-arg DB_PASS=$(DB_PASS) \ + --platform linux/amd64 \ + -t git.kohout-dev.de/crowsnest/crowsnest:latest .