Skip to content

Commit

Permalink
chore: Split up docker files and upgrade docker compose (#1333)
Browse files Browse the repository at this point in the history
* Split docker compose into environments
* Upgrade docker-compose
* Update all workflow OS versions to Ubuntu 22.04 (LTS)
  • Loading branch information
builditben authored Feb 6, 2023
1 parent 90cf07a commit 1198865
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pizza-teardown-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:

jobs:
teardown_pizza:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Remove vultr resources
uses: theopensystemslab/vultr-action@v1.15
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pizza-teardown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:

jobs:
teardown_pizza:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Remove vultr resources
uses: theopensystemslab/vultr-action@v1.15
Expand Down
43 changes: 21 additions & 22 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
jobs:
changes:
name: Check file changes
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
permissions:
pull-requests: read
outputs:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
integration_tests:
name: Run Integration tests
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.api == 'true' || needs.changes.outputs.e2e == 'true' || needs.changes.outputs.editor == 'true' || needs.changes.outputs.sharedb == 'true' || needs.changes.outputs.hasura == 'true' }}
steps:
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:

api_tests:
name: Run API Tests
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 10
needs: [changes]
if: ${{ needs.changes.outputs.api == 'true' }}
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:

test_react:
name: Run React Tests
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.editor == 'true' }}
steps:
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:

build_react_app:
name: Build React App
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [changes]
if: "${{ !contains(needs.changes.outputs.commit, '[skip pizza]') }}"
steps:
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:

build_storybook:
name: Build Storybook
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [changes]
if: "${{ !contains(needs.changes.outputs.commit, '[skip pizza]') }}"
steps:
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:

pulumi_preview:
name: Run Pulumi Preview
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [changes, build_react_app]
if: ${{ needs.changes.outputs.infrastructure == 'true' }}
steps:
Expand Down Expand Up @@ -294,7 +294,7 @@ jobs:

hasura-change-summary:
name: Generate Hasura Change Summary
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.hasura == 'true' }}
steps:
Expand All @@ -321,7 +321,7 @@ jobs:
create_or_update_vultr_instance:
name: Upsert Vultr Instance
needs: [changes, build_react_app, build_storybook]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: "${{ success() && !contains(needs.changes.outputs.commit, '[skip pizza]') }}"
steps:
- name: Create Pizza (if it doesn't exist)
Expand All @@ -331,7 +331,7 @@ jobs:
action: create
api_key: ${{ secrets.VULTR_API_KEY }}
domain: ${{ env.DOMAIN }}
os_id: 387
os_id: 1743
plan: vc2-1c-1gb
pullrequest_id: ${{ env.PULLREQUEST_ID }}
region: lhr
Expand Down Expand Up @@ -359,12 +359,10 @@ jobs:
./scripts/pull-secrets.sh
echo "
ROOT_DOMAIN=${{ env.FULL_DOMAIN }}
" > .env.temp
cat .env .env.temp .env.staging > .env.prod
echo -e "\nROOT_DOMAIN=${{ env.FULL_DOMAIN }}\n" > .env.temp
cat .env .env.temp .env.staging > .env.pizza
SSH_PASSWORD=${{ secrets.SSH_PASSWORD }} sh scripts/pullrequest/create.sh
SSH_PASSWORD=${{ secrets.SSH_PASSWORD }} ./scripts/pullrequest/create.sh
# UPDATE STEPS

Expand All @@ -389,12 +387,10 @@ jobs:
./scripts/pull-secrets.sh
echo "
ROOT_DOMAIN=${{ env.FULL_DOMAIN }}
" > .env.temp
cat .env .env.temp .env.staging > .env.prod
echo -e "\nROOT_DOMAIN=${{ env.FULL_DOMAIN }}\n" > .env.temp
cat .env .env.temp .env.staging > .env.pizza
sh scripts/pullrequest/update.sh
./scripts/pullrequest/update.sh
# CREATE & UPDATE STEPS

Expand Down Expand Up @@ -440,22 +436,25 @@ jobs:
healthcheck:
name: Run Healthcheck on Pizza Services
needs: [create_or_update_vultr_instance]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: API healthcheck
run: |
timeout 150s bash -c "until curl --fail https://api.${{ env.FULL_DOMAIN }}; do sleep 1; done"
- name: Hasura healthcheck
run: |
timeout 150s bash -c "until curl --fail https://hasura.${{ env.FULL_DOMAIN }}/healthz; do sleep 1; done"
- name: Editor healthcheck
run: |
timeout 150s bash -c "until curl --fail https://${{ env.FULL_DOMAIN }}; do sleep 1; done"
lighthouse:
name: Lighthouse
needs: [create_or_update_vultr_instance]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Audit URLs using Lighthouse
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
jobs:
build_react:
name: Build React
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
preview:
name: Pulumi Up
needs: build_react
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
notifications:
name: Notifications
needs: preview
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
# Airbrake notification - https://airbrake.io/docs/features/deploy-tracking
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
jobs:
build_react:
name: Test and Build
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
preview:
name: Pulumi Up
needs: build_react
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
notifications:
name: Notifications
needs: preview
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
# Airbrake notification - https://airbrake.io/docs/features/deploy-tracking
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ planx-new is a monorepo containing our full application stack. Here's a quick su
- `sharedb.planx.uk` is our implementation of [ShareDB](https://github.com/share/sharedb), a library for realtime document collaboration based on JSON Operational Transformation (OT) used in our "editor" environment
- `infrastructure` is [Pulumi](https://www.pulumi.com/) infrastructure-as-code for configuring and managing our AWS environments


## Running Locally

1. Download and install the following dependencies if you don't have them already:
Expand All @@ -26,31 +27,30 @@ planx-new is a monorepo containing our full application stack. Here's a quick su

1. Clone this repository. You'll need to get some additional environment variable files that aren't published here. Find instructions for copying these in 1password under the AWS Staging IAM user role entry

1. Run the following command to get everything (postgres, sharedb, api and hasura server processes) up and running `docker-compose up --build -d`
1. Run `pnpm docker:up` from the project root to get everything (postgres, sharedb, api and hasura server processes) up and running and `pnpm docker:down` to stop all services. `pnpm docker:down-hard` will remove volumes (i.e. database data) and can be a useful hard reset when necessary.

1. Move into the hasura directory `cd ../hasura.planx.uk` & install dependencies `pnpm i`.

1. Open [Hasura's](https://hasura.io/) web console `pnpm start` & check that your Google email address is in the `users` table, if not then add it
1. Open [Hasura's](https://hasura.io/) web console (`cd hasura.planx.uk` then `pnpm start`) & check that your Google email address is in the `users` table, if not then add it

1. Move into the editor directory `cd ../editor.planx.uk` & install dependencies `pnpm i`.

1. Start the dev server! `pnpm start` & open http://localhost:3000 & login with your GMail/Google email address
1. Start the editor dev server! `pnpm start` & open `http://localhost:3000` & login with your GMail/Google email address


### Troubleshooting

If you run into trouble, you may want to try the following:

* Ensure you have a local `.env` file with up-to-date keys etc (see relevant `.env.example` files for reference and 1Password for an initial `.env` file).
* The Hasura CLI may require a postinstall step which can be run manually with `cd node_modules/hasura-cli && pnpm postinstall`.


### Analytics

Running `docker-compose up` won't spin up [Metabase](https://www.metabase.com/).
Running `docker compose up` won't spin up [Metabase](https://www.metabase.com/).
To spin it up, run:

`docker-compose --profile analytics up`
`docker compose --profile analytics up`


### Documentation
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.8"

services:
postgres:
volumes:
- postgres_data:/var/lib/postgresql/data

api:
build:
target: development
volumes:
- "./api.planx.uk:/api"

sharedb:
volumes:
- "./sharedb.planx.uk:/sharedb"
- "/sharedb/node_modules"

volumes:
postgres_data:
11 changes: 8 additions & 3 deletions docker-compose.pizza.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
version: "3.8"

# If you change anything here (e.g. environment variables)
# remember to cascade the change to `infrastructure/`

services:
postgres:
volumes:
- postgres_data:/var/lib/postgresql/data
labels:
virtual.host: postgres.${ROOT_DOMAIN}
virtual.port: 5432
Expand All @@ -19,6 +24,8 @@ services:
virtual.tls: ${TLS_EMAIL}

api:
build:
target: production
volumes:
- "/api/node_modules"
- "/api/dist"
Expand All @@ -35,9 +42,6 @@ services:
virtual.port: 8000
virtual.tls: ${TLS_EMAIL}

minio:
entrypoint: ["echo", "minio disabled"]

editor:
image: pierrezemb/gostatic
volumes:
Expand All @@ -59,5 +63,6 @@ services:
- 443:443

volumes:
postgres_data:
caddy_data:
caddy_config:
Loading

0 comments on commit 1198865

Please sign in to comment.