Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
entrypoint for docker image, apply migration on start up
Browse files Browse the repository at this point in the history
  • Loading branch information
ramilexe committed Feb 12, 2021
1 parent d042f85 commit 89363e8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ ADD . /go/src/github.com/vulcanize/tracing-api
WORKDIR /go/src/github.com/vulcanize/tracing-api
RUN make linux

# Build migration tool
WORKDIR /
RUN go get -u -d github.com/pressly/goose/cmd/goose
WORKDIR /go/src/github.com/pressly/goose/cmd/goose
RUN GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -tags='no_mysql no_sqlite' -o goose .

# app container
FROM alpine

WORKDIR /app

# keep binaries immutable
COPY --from=builder /go/src/github.com/vulcanize/tracing-api/build/tracer-linux /usr/local/bin/tracer
COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose /usr/local/bin/goose
COPY --from=builder /go/src/github.com/vulcanize/tracing-api/startup_script.sh .
COPY --from=builder /go/src/github.com/vulcanize/tracing-api/db/migrations migrations

EXPOSE 8080

ENTRYPOINT ["tracer"]
ENTRYPOINT ["/app/startup_script.sh"]
21 changes: 21 additions & 0 deletions startup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# Runs the db migrations and starts the service

set +x

# Construct the connection string for postgres
VDB_PG_CONNECT=postgresql://$CACHE_DATABASE_USER:$CACHE_DATABASE_PASSWORD@$CACHE_DATABASE_HOSTNAME:$CACHE_DATABASE_PORT/$CACHE_DATABASE_NAME?sslmode=disable

# Run the DB migrations
echo "Connecting with: $VDB_PG_CONNECT"
echo "Running database migrations"
goose -table goose_db_version_trace -dir migrations postgres "$VDB_PG_CONNECT" up

# If the db migrations ran without err
if [[ $? -ne 0 ]]; then
echo "Could not run migrations. Are the database details correct?"
exit 1
fi

echo "Running the Tracing-API process"
exec tracer "$@"

0 comments on commit 89363e8

Please sign in to comment.