diff --git a/Dockerfile b/Dockerfile index 609f180498..00feadd925 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Dockerfile.db_clean b/Dockerfile.db_clean index bd0999fc07..c1f6b53f18 100644 --- a/Dockerfile.db_clean +++ b/Dockerfile.db_clean @@ -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"] diff --git a/Dockerfile.db_migrations b/Dockerfile.db_migrations index 378b7a732b..9900ba0956 100644 --- a/Dockerfile.db_migrations +++ b/Dockerfile.db_migrations @@ -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"] diff --git a/Dockerfile.db_seed b/Dockerfile.db_seed deleted file mode 100644 index fc441fd122..0000000000 --- a/Dockerfile.db_seed +++ /dev/null @@ -1,16 +0,0 @@ -FROM golang:1.21 AS base - -WORKDIR /mint/ - -FROM base AS modules - -COPY go.mod ./ -COPY go.sum ./ -RUN go mod download - -FROM modules AS build - -COPY cmd ./cmd -COPY pkg ./pkg - -ENTRYPOINT ["go", "run", "cmd/devdata/main.go"] diff --git a/docker-compose.backend.yml b/docker-compose.backend.yml index 866f7d638a..c70c0e8875 100644 --- a/docker-compose.backend.yml +++ b/docker-compose.backend.yml @@ -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: diff --git a/docs/local_testing.md b/docs/local_testing.md index 83928e9445..062e952e98 100644 --- a/docs/local_testing.md +++ b/docs/local_testing.md @@ -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. diff --git a/scripts/run-cypress-test-docker b/scripts/run-cypress-test-docker deleted file mode 100755 index a965b31215..0000000000 --- a/scripts/run-cypress-test-docker +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail - -PROJECT_NAME=mint-app -CYPRESS_CONTAINER="${PROJECT_NAME}"_cypress_1 -MINT_CONTAINER="${PROJECT_NAME}"_mint_1 - -# Running in CI -if [[ -n "${CI+x}" ]]; then - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml pull db_migrate mint - - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml build --parallel - - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up -d db - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up --exit-code-from db_migrate db_migrate - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up --exit-code-from db_seed db_seed - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up -d minio - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up --exit-code-from minio_mc minio_mc - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up -d mint mint_client - - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_ci.yml up cypress - - docker container cp "${CYPRESS_CONTAINER}":/cypress/screenshots cypress/ || echo "No cypress screenshots copied" - docker container cp "${CYPRESS_CONTAINER}":/cypress/videos cypress/ || echo "No cypress videos copied" - CYPRESS_EXIT_CODE=$(docker container inspect --format='{{.State.ExitCode}}' "${CYPRESS_CONTAINER}") - echo "done" - exit "${CYPRESS_EXIT_CODE}" -# Running locally -else - # Clean up first - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml down - - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml build --parallel - - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up -d db - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up --exit-code-from db_migrate db_migrate - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up --exit-code-from db_seed db_seed - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up -d minio - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up --exit-code-from minio_mc minio_mc - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up -d mint mint_client - - MINT_EXIT_CODE=$(docker container inspect --format='{{.State.ExitCode}}' "${MINT_CONTAINER}") - - if [[ "${MINT_EXIT_CODE}" -ne 0 ]]; then - echo "Docker container ${MINT_CONTAINER} exited unexpectedly. No tests will be run." - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml logs --tail="all" mint - exit 1 - fi - - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml up cypress - - CYPRESS_EXIT_CODE=$(docker container inspect --format='{{.State.ExitCode}}' "${CYPRESS_CONTAINER}") - - # Clean up - docker-compose --project-name "${PROJECT_NAME}" -f docker-compose.yml -f docker-compose.cypress_local.yml down - - exit "${CYPRESS_EXIT_CODE}" -fi