Skip to content

Commit

Permalink
EASI-3163: Refactor MINT Dockerfiles (#723)
Browse files Browse the repository at this point in the history
* EASI-3350: refactor Dockerfile

* EASI-3353: TAG default value, ENV in single line

* EASI-3352: ENV layer to single line

* EASI-3355: db_seed change to golang:1.21-alpine

* remove run-cypress-test-docker as unused and out of date

* EASI-3355: remove unused dockerfile

* linting

* lint! i'm an idiot

* EASI-3350: copy from base for certs and tzinfo for cache

* EASI-3353: remove duplicative default value TAG=9.10

---------

Co-authored-by: Clay Benson <[email protected]>
  • Loading branch information
Jdwoodson and ClayBenson94 authored Oct 2, 2023
1 parent a672624 commit 78a6fb2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 126 deletions.
66 changes: 32 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
FROM golang:1.21 AS base

WORKDIR /mint/

# Copy certificates
COPY config/tls/*.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates && \
apt install tzdata && \
rm -rf /var/lib/apt/lists/*

# Copy go.mod and go.sum files to the workspace and download dependencies
COPY go.mod ./
COPY go.sum ./
RUN go mod download
WORKDIR /mint/

# Copy certificates
COPY config/tls/*.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates && \
apt update && \
apt install -y tzdata && \
rm -rf /var/lib/apt/lists/*

# Copy go.mod and go.sum files to the workspace and download dependencies
COPY go.mod go.sum ./
RUN go mod download

FROM base AS dev

# Install delve, gopls, and air for debugging
RUN go install github.com/go-delve/delve/cmd/dlv@latest && \
go install golang.org/x/tools/gopls@latest && \
go install github.com/cosmtrek/air@4612c12f1ed7c899314b8430bc1d841ca2cb061a
# Install delve, gopls, and air for debugging
RUN go install github.com/go-delve/delve/cmd/dlv@latest && \
go install golang.org/x/tools/gopls@latest && \
go install github.com/cosmtrek/air@4612c12f1ed7c899314b8430bc1d841ca2cb061a

FROM base AS build

COPY cmd ./cmd
COPY pkg ./pkg
RUN CGO_ENABLED=0 GOOS=linux go build -a -o bin/mint ./cmd/mint
COPY cmd/ pkg/ ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -o bin/mint ./cmd/mint

FROM scratch

WORKDIR /mint/

COPY --from=build /mint/bin/mint .
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo
WORKDIR /mint/

# Copy build args to envs for version, datetime, and timestamp
ARG ARG_APPLICATION_VERSION
ARG ARG_APPLICATION_DATETIME
ARG ARG_APPLICATION_TS
ENV APPLICATION_VERSION=${ARG_APPLICATION_VERSION}
ENV APPLICATION_DATETIME=${ARG_APPLICATION_DATETIME}
ENV APPLICATION_TS=${ARG_APPLICATION_TS}
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build /mint/bin/mint ./

USER 1000
# Copy build args to envs for version, datetime, and timestamp
ARG ARG_APPLICATION_VERSION
ARG ARG_APPLICATION_DATETIME
ARG ARG_APPLICATION_TS
ENV APPLICATION_VERSION=${ARG_APPLICATION_VERSION} \
APPLICATION_DATETIME=${ARG_APPLICATION_DATETIME} \
APPLICATION_TS=${ARG_APPLICATION_TS}

ENTRYPOINT ["/mint/mint"]
USER 1000

CMD ["serve"]
ENTRYPOINT ["/mint/mint"]
CMD ["serve"]
10 changes: 5 additions & 5 deletions Dockerfile.db_clean
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM flyway/flyway:9.10-alpine

ENV FLYWAY_CONNECT_RETRIES=10
ENV FLYWAY_IGNORE_INVALID_MIGRATION_NAMES="false"
ENV FLYWAY_SCHEMAS=audit,public
ENV FLYWAY_DEFAULT_SCHEMA=public
ENV FLYWAY_CLEAN_DISABLED="false"
ENV FLYWAY_CONNECT_RETRIES=10 \
FLYWAY_IGNORE_INVALID_MIGRATION_NAMES="false" \
FLYWAY_SCHEMAS=audit,public \
FLYWAY_DEFAULT_SCHEMA=public \
FLYWAY_CLEAN_DISABLED="false"

ENTRYPOINT ["flyway", "clean"]
12 changes: 6 additions & 6 deletions Dockerfile.db_migrations
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ARG TAG=
ARG TAG=9.10
FROM flyway/flyway:${TAG}

COPY migrations/ /flyway/sql

ENV FLYWAY_CONNECT_RETRIES=10
ENV FLYWAY_CLEAN_DISABLED="true"
ENV FLYWAY_SCHEMAS=public
ENV FLYWAY_DEFAULT_SCHEMA=public
ENV FLYWAY_CONNECT_RETRIES=10 \
FLYWAY_CLEAN_DISABLED="true" \
FLYWAY_SCHEMAS=public \
FLYWAY_DEFAULT_SCHEMA=public

ENTRYPOINT ["flyway", "-validateMigrationNaming=true", "migrate" ]
ENTRYPOINT ["flyway", "-validateMigrationNaming=true", "migrate"]
16 changes: 0 additions & 16 deletions Dockerfile.db_seed

This file was deleted.

2 changes: 0 additions & 2 deletions docker-compose.backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ services:
- ./migrations:/flyway/sql
image: mint-db-migrate:latest
build:
args:
TAG: '9.10' # Multi arch tag, rather than '9.10-alpine'
context: .
dockerfile: Dockerfile.db_migrations
environment:
Expand Down
4 changes: 0 additions & 4 deletions docs/local_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ There are multiple ways to run the Cypress tests:
- Note: the database, frontend, and backend must be running prior to starting the Cypress tests. Use `scripts/dev up` to start them.
- The `APP_ENV` environment variable should be set to `testing` in `.envrc.local`. After creating `.envrc.local` if necessary and adding `APP_ENV=testing` to it, run `direnv allow` to enable it. (See [instructions above](#direnv) on `direnv` usage)
- Running `login.spec.js` requires the environment variables `OKTA_TEST_USERNAME`, `OKTA_TEST_PASSWORD`, and `OKTA_TEST_SECRET` to be set in `.envrc.local`. The values can be found in 1Password, as mentioned in the [Authentication section](#authentication).
- `APP_ENV=testing ./scripts/run-cypress-test-docker` : Run the Cypress tests,
database, migrations, backend, and frontend locally in Docker, similar to how
they run in CI. Running the tests in this way takes time, but is useful
for troubleshooting integration test failures in CI.
59 changes: 0 additions & 59 deletions scripts/run-cypress-test-docker

This file was deleted.

0 comments on commit 78a6fb2

Please sign in to comment.