Skip to content

Commit

Permalink
feat: Remove hasura-proxy service
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Dec 16, 2024
1 parent 3c0358f commit 7c42c41
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 110 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ EDITOR_URL_EXT=http://localhost:3000

# Hasura
HASURA_GRAPHQL_ADMIN_SECRET=👻
HASURA_PROXY_PORT=7100
HASURA_GRAPHQL_URL=http://localhost:${HASURA_PROXY_PORT}/v1/graphql
HASURA_GRAPHQL_PORT=7100
HASURA_GRAPHQL_URL=http://localhost:${HASURA_GRAPHQL_PORT}/v1/graphql
HASURA_CONSOLE_PORT=9695
HASURA_GRAPHQL_CORS_DOMAIN="http://localhost:${API_PORT}, http://localhost:${HASURA_CONSOLE_PORT}, http://localhost:3000, http://api:${API_PORT}, http://localhost:${HASURA_PROXY_PORT}/v1/graphql, https://*.planx.uk, https://*.planx.dev, https://*.planx.pizza, https://*.gov.uk"
HASURA_GRAPHQL_CORS_DOMAIN="http://localhost:${API_PORT}, http://localhost:${HASURA_CONSOLE_PORT}, http://localhost:3000, http://api:${API_PORT}, http://localhost:${HASURA_GRAPHQL_PORT}/v1/graphql, https://*.planx.uk, https://*.planx.dev, https://*.planx.pizza, https://*.gov.uk"

# Hasura Metadata API
HASURA_PLANX_API_URL=http://api:${API_PORT}
Expand Down
7 changes: 1 addition & 6 deletions docker-compose.pizza.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ services:
virtual.tls-email: ${TLS_EMAIL}

hasura:
labels:
virtual.port: 8080
virtual.tls-email: ${TLS_EMAIL}

hasura-proxy:
labels:
virtual.host: hasura.${ROOT_DOMAIN}
virtual.port: ${HASURA_PROXY_PORT}
virtual.port: 8080
virtual.tls-email: ${TLS_EMAIL}

api:
Expand Down
30 changes: 7 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ services:
hasura:
build:
context: ./hasura.planx.uk
ports:
- ${HASURA_GRAPHQL_PORT}:8080
depends_on:
postgres:
condition: service_healthy
Expand Down Expand Up @@ -77,31 +79,13 @@ services:
HASURA_PLANX_API_KEY: ${HASURA_PLANX_API_KEY}
HASURA_PLANX_API_URL: ${HASURA_PLANX_API_URL}

hasura-proxy:
build:
context: ./hasura.planx.uk/proxy
depends_on:
hasura:
condition: service_healthy
restart: always
ports:
- ${HASURA_PROXY_PORT}:${HASURA_PROXY_PORT}
environment:
HASURA_PROXY_PORT: ${HASURA_PROXY_PORT}
HASURA_NETWORK_LOCATION: "hasura"
healthcheck:
test: ["CMD", "wget", "--spider", "--quiet", "localhost:$HASURA_PROXY_PORT/healthz"]
interval: 15s
timeout: 3s
retries: 3

api:
restart: unless-stopped
build:
context: ./api.planx.uk
target: production
depends_on:
hasura-proxy:
hasura:
condition: service_healthy
ports:
- ${API_PORT}:${API_PORT}
Expand Down Expand Up @@ -137,10 +121,10 @@ services:
MICROSOFT_CLIENT_SECRET: ${MICROSOFT_CLIENT_SECRET}
GOVUK_NOTIFY_API_KEY: ${GOVUK_NOTIFY_API_KEY}
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
HASURA_GRAPHQL_URL: http://hasura-proxy:${HASURA_PROXY_PORT}/v1/graphql
HASURA_METADATA_URL: http://hasura-proxy:${HASURA_PROXY_PORT}/v1/metadata
HASURA_GRAPHQL_URL: http://hasura:8080/v1/graphql
HASURA_GRAPHQL_ENDPOINT: http://hasura:8080/
HASURA_PLANX_API_KEY: ${HASURA_PLANX_API_KEY}
HASURA_SCHEMA_URL: http://hasura-proxy:${HASURA_PROXY_PORT}/v2/query
HASURA_SCHEMA_URL: http://hasura:8080/v2/query
IDOX_NEXUS_CLIENT: ${IDOX_NEXUS_CLIENT}
IDOX_NEXUS_SUBMISSION_URL: ${IDOX_NEXUS_SUBMISSION_URL}
IDOX_NEXUS_TOKEN_URL: ${IDOX_NEXUS_TOKEN_URL}
Expand Down Expand Up @@ -174,7 +158,7 @@ services:
- "./sharedb.planx.uk:/sharedb"
- "/sharedb/node_modules"
depends_on:
hasura-proxy:
hasura:
condition: service_healthy
ports:
- ${SHAREDB_PORT}:8000
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/api-driven/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ assert(process.env.HASURA_GRAPHQL_ADMIN_SECRET);
assert(process.env.HASURA_GRAPHQL_URL);

const targetURL = process.env.HASURA_GRAPHQL_URL!.replace(
"${HASURA_PROXY_PORT}",
process.env.HASURA_PROXY_PORT!,
"${HASURA_GRAPHQL_PORT}",
process.env.HASURA_GRAPHQL_PORT!,
);

export const $admin = new CoreDomainClient({
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export function getCoreDomainClient(): CoreDomainClient {
assert(process.env.HASURA_GRAPHQL_ADMIN_SECRET);

const API = process.env.HASURA_GRAPHQL_URL!.replace(
"${HASURA_PROXY_PORT}",
process.env.HASURA_PROXY_PORT!,
"${HASURA_GRAPHQL_PORT}",
process.env.HASURA_GRAPHQL_PORT!,
);
const SECRET = process.env.HASURA_GRAPHQL_ADMIN_SECRET!;
return new CoreDomainClient({
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/ui-driven/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import Axios from "axios";

export const gqlAdmin = async (query, variables = {}) => {
const HASURA_GRAPHQL_ADMIN_SECRET = process.env.HASURA_GRAPHQL_ADMIN_SECRET;
const HASURA_PROXY_PORT = process.env.HASURA_PROXY_PORT;
const HASURA_GRAPHQL_PORT = process.env.HASURA_GRAPHQL_PORT;

const response = await Axios(
`http://localhost:${HASURA_PROXY_PORT}/v1/graphql`,
`http://localhost:${HASURA_GRAPHQL_PORT}/v1/graphql`,
{
method: "POST",
headers: {
"X-Hasura-Admin-Secret": HASURA_GRAPHQL_ADMIN_SECRET,
},
data: { query, variables },
},
}
);
const { data: json } = response;

Expand Down
29 changes: 0 additions & 29 deletions hasura.planx.uk/proxy/Caddyfile

This file was deleted.

2 changes: 0 additions & 2 deletions hasura.planx.uk/proxy/Dockerfile

This file was deleted.

24 changes: 0 additions & 24 deletions hasura.planx.uk/proxy/README.md

This file was deleted.

1 change: 0 additions & 1 deletion hasura.planx.uk/proxy/run-caddy-shell.sh

This file was deleted.

17 changes: 2 additions & 15 deletions infrastructure/application/services/hasura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const createHasuraService = async ({
subnets: networking.requireOutput("publicSubnetIds"),
});
// XXX: If you change the port, you'll have to make the security group accept incoming connections on the new port
const HASURA_PROXY_PORT = 80;
const HASURA_GRAPHQL_PORT = 80;
const targetHasura = lbHasura.createTargetGroup("hasura", {
port: HASURA_PROXY_PORT,
port: HASURA_GRAPHQL_PORT,
protocol: "HTTP",
healthCheck: {
path: "/healthz",
Expand All @@ -45,9 +45,6 @@ export const createHasuraService = async ({
domain: DOMAIN,
});

// hasuraService is composed of two tightly coupled containers
// hasuraProxy is publicly exposed (behind the load balancer) and reverse proxies requests to hasura
// hasura has no externally exposed ports, and can only be accessed by hasuraService
const hasuraService = new awsx.ecs.FargateService("hasura", {
cluster,
subnets: networking.requireOutput("publicSubnetIds"),
Expand All @@ -57,16 +54,6 @@ export const createHasuraService = async ({
retentionInDays: 30,
}),
containers: {
hasuraProxy: {
image: repo.buildAndPushImage("../../hasura.planx.uk/proxy"),
cpu: config.requireNumber("hasura-proxy-cpu"),
memory: config.requireNumber("hasura-proxy-memory"),
portMappings: [hasuraListenerHttp],
environment: [
{ name: "HASURA_PROXY_PORT", value: String(HASURA_PROXY_PORT) },
{ name: "HASURA_NETWORK_LOCATION", value: "localhost" },
],
},
hasura: {
image: repo.buildAndPushImage("../../hasura.planx.uk"),
cpu: config.requireNumber("hasura-cpu"),
Expand Down

0 comments on commit 7c42c41

Please sign in to comment.