From 089a8002fb83d84fb94cea7cd04368edbdc40199 Mon Sep 17 00:00:00 2001 From: tangoyankee Date: Mon, 7 Oct 2024 15:14:47 -0400 Subject: [PATCH] Align github action with local development - Build action from a compose file, bringing the action config and local config closer together - Add environment variable closes #59 --- .github/workflows/update-api-database.yml | 40 +++++++++++------------ common-services.yml | 17 ++++++++++ compose.ci.yml | 5 +++ compose.yml | 18 ++-------- db/Dockerfile | 4 +-- pg/pg-connector.ts | 3 ++ 6 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 common-services.yml create mode 100644 compose.ci.yml diff --git a/.github/workflows/update-api-database.yml b/.github/workflows/update-api-database.yml index 11a2b83..5e5d172 100644 --- a/.github/workflows/update-api-database.yml +++ b/.github/workflows/update-api-database.yml @@ -20,35 +20,35 @@ on: options: - staging - production - jobs: update: environment: name: ${{ inputs.environment }} + env: + DO_SPACES_ACCESS_KEY: ${{ secrets.DO_SPACES_ACCESS_KEY }} + DO_SPACES_ENDPOINT: ${{ secrets.DO_SPACES_ENDPOINT }} + DO_SPACES_SECRET_KEY: ${{ secrets.DO_SPACES_SECRET_KEY }} + FLOW_DATABASE_ENV: ${{ secrets.FLOW_DATABASE_ENV }} + FLOW_DATABASE_HOST: ${{ secrets.FLOW_DATABASE_HOST }} + FLOW_DATABASE_NAME: ${{ secrets.FLOW_DATABASE_NAME }} + FLOW_DATABASE_PASSWORD: ${{ secrets.FLOW_DATABASE_PASSWORD }} + FLOW_DATABASE_PORT: ${{ secrets.FLOW_DATABASE_PORT }} + FLOW_DATABASE_USER: ${{ secrets.FLOW_DATABASE_USER }} + TARGET_DATABASE_HOST: ${{ secrets.TARGET_DATABASE_HOST }} + TARGET_DATABASE_NAME: ${{ secrets.TARGET_DATABASE_NAME }} + TARGET_DATABASE_PASSWORD: ${{ secrets.TARGET_DATABASE_PASSWORD }} + TARGET_DATABASE_PORT: ${{ secrets.TARGET_DATABASE_PORT }} + TARGET_DATABASE_USER: ${{ secrets.TARGET_DATABASE_USER }} + name: Update database runs-on: ubuntu-latest - services: - postgres: - image: postgis/postgis:15-3.4-alpine - env: - POSTGRES_USER: ${{ secrets.FLOW_DATABASE_USER }} - POSTGRES_PASSWORD: ${{ secrets.FLOW_DATABASE_PASSWORD }} - POSTGRES_DB: ${{ secrets.FLOW_DATABASE_NAME }} - TARGET_DATABASE_USER: ${{ secrets.TARGET_DATABASE_USER }} - TARGET_DATABASE_PASSWORD: ${{ secrets.TARGET_DATABASE_PASSWORD }} - TARGET_DATABASE_NAME: ${{ secrets.TARGET_DATABASE_NAME }} - TARGET_DATABASE_PORT: ${{ secrets.TARGET_DATABASE_PORT }} - TARGET_DATABASE_HOST: ${{ secrets.TARGET_DATABASE_HOST }} - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 steps: - name: checkout code uses: actions/checkout@v4 + - name: Initialize database service from compose + uses: hoverkraft-tech/compose-action@v2.0.2 + with: + compose-file: "compose.ci.yml" - name: install node uses: actions/setup-node@v4 with: diff --git a/common-services.yml b/common-services.yml new file mode 100644 index 0000000..7dec72f --- /dev/null +++ b/common-services.yml @@ -0,0 +1,17 @@ +services: + postgis: + build: + context: db/. + environment: + - POSTGRES_USER=${FLOW_DATABASE_USER} + - POSTGRES_PASSWORD=${FLOW_DATABASE_PASSWORD} + - POSTGRES_DB=${FLOW_DATABASE_NAME} + - TARGET_DATABASE_USER=${TARGET_DATABASE_USER} + - TARGET_DATABASE_PASSWORD=${TARGET_DATABASE_PASSWORD} + - TARGET_DATABASE_NAME=${TARGET_DATABASE_NAME} + - TARGET_DATABASE_PORT=${TARGET_DATABASE_PORT} + - TARGET_DATABASE_HOST=${TARGET_DATABASE_HOST} + ports: + - $FLOW_DATABASE_PORT:5432 + volumes: + - ./db/pg:/var/lib/postgresql/flow diff --git a/compose.ci.yml b/compose.ci.yml new file mode 100644 index 0000000..642ce2a --- /dev/null +++ b/compose.ci.yml @@ -0,0 +1,5 @@ +services: + db: + extends: + file: common-services.yml + service: postgis diff --git a/compose.yml b/compose.yml index a102f6d..b1798eb 100644 --- a/compose.yml +++ b/compose.yml @@ -1,22 +1,10 @@ services: db: - build: - context: db/. - environment: - - POSTGRES_USER=${FLOW_DATABASE_USER} - - POSTGRES_PASSWORD=${FLOW_DATABASE_PASSWORD} - - POSTGRES_DB=${FLOW_DATABASE_NAME} - - TARGET_DATABASE_USER=${TARGET_DATABASE_USER} - - TARGET_DATABASE_PASSWORD=${TARGET_DATABASE_PASSWORD} - - TARGET_DATABASE_NAME=${TARGET_DATABASE_NAME} - - TARGET_DATABASE_PORT=${TARGET_DATABASE_PORT} - - TARGET_DATABASE_HOST=${TARGET_DATABASE_HOST} + extends: + file: common-services.yml + service: postgis networks: - data - ports: - - "8001:5432" - volumes: - - ./db/pg:/var/lib/postgresql/flow networks: data: name: ae-zoning-api_data diff --git a/db/Dockerfile b/db/Dockerfile index 60d6b7a..a48150f 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -1,6 +1,6 @@ FROM postgres:15-bookworm -RUN apt update -RUN apt install -y postgresql-15-postgis-3 +RUN apt-get update +RUN apt-get install -y postgresql-15-postgis-3 WORKDIR /var/lib/postgresql diff --git a/pg/pg-connector.ts b/pg/pg-connector.ts index d7217b2..817f502 100644 --- a/pg/pg-connector.ts +++ b/pg/pg-connector.ts @@ -7,6 +7,9 @@ const credentials = { user: process.env.FLOW_DATABASE_USER, password: process.env.FLOW_DATABASE_PASSWORD, database: process.env.FLOW_DATABASE_NAME!, + ssl: process.env.FLOW_DATABASE_ENV !== "development" && { + rejectUnauthorized: false, + }, }; export const pgClient = new Client(credentials);