Skip to content

Commit 373efcf

Browse files
committed
build hackernews app docker container
1 parent b71da2a commit 373efcf

File tree

7 files changed

+137
-8
lines changed

7 files changed

+137
-8
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
cmd: yq -i 'del(.services.*.volumes)' examples/hackernews/docker-compose.yml
110110

111111
- name: Start Docker
112-
run: docker compose -f examples/hackernews/docker-compose.yml up -d --wait
112+
run: docker compose -f examples/hackernews/docker-compose.yml up -d --wait postgres
113113

114114
- name: Run Tests
115115
uses: nick-fields/retry@v3
@@ -271,6 +271,30 @@ jobs:
271271
failOnRequired: true
272272
debug: true
273273

274+
hackernews-docker-container:
275+
runs-on: ubuntu-latest
276+
steps:
277+
- name: Checkout Repository
278+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
279+
280+
- name: Setup env
281+
uses: the-guild-org/shared-config/setup@main
282+
with:
283+
nodeVersion: 22
284+
packageManager: pnpm
285+
286+
- name: Build Packages
287+
run: pnpm build
288+
289+
- name: Build Hackernews App
290+
run: pnpm --filter=example-hackernews build
291+
292+
- name: Isolate Docker Image Build Context
293+
run: pnpm build:hackernews:docker
294+
295+
- name: Build Hackernews Docker Image
296+
run: docker compose -f .hackernews-deploy/docker-compose.yml build api
297+
274298
# TODO: have the example and packages use singleton nestjs dependencies
275299
# but without using .pnpmfile.cjs because it causes issues with renovate: https://github.com/dotansimha/graphql-yoga/pull/2622
276300
# nestjs-apollo-federation-compatibility:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ packages/graphql-yoga/src/graphiql-html.ts
1818
.tool-versions
1919

2020
.mise.toml
21+
.hackernews-deploy

examples/hackernews/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:22-slim
2+
3+
RUN apt-get update && apt-get install -y ca-certificates
4+
5+
WORKDIR /usr/src/app
6+
7+
COPY ./package.json /usr/src/app
8+
COPY ./node_modules /usr/src/app/node_modules
9+
10+
COPY ./dist/src/ /usr/src/app/
11+
12+
LABEL org.opencontainers.image.title="Hackernews GraphQL Server"
13+
LABEL org.opencontainers.image.version=$RELEASE
14+
LABEL org.opencontainers.image.description="A Hackernews clone built with GraphQL and graphql-yoga."
15+
LABEL org.opencontainers.image.authors="The Guild"
16+
LABEL org.opencontainers.image.vendor="Laurin Quast"
17+
LABEL org.opencontainers.image.url="https://github.com/dotansimha/graphql-yoga/tree/main/examples/hackernews"
18+
LABEL org.opencontainers.image.source="https://github.com/dotansimha/graphql-yoga/tree/main/examples/hackernews"
19+
20+
ENV ENVIRONMENT production
21+
ENV RELEASE $RELEASE
22+
23+
ENTRYPOINT ["node", "main.js"]

examples/hackernews/docker-compose.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: '3.8'
22
services:
3-
db:
3+
postgres:
44
image: postgres:14.12-alpine
55
networks:
66
- 'stack'
@@ -19,5 +19,24 @@ services:
1919
ports:
2020
- '5432:5432'
2121

22+
api:
23+
image: ${DOCKER_REGISTRY}yoga-hackernews${DOCKER_TAG}
24+
build:
25+
context: .
26+
dockerfile: Dockerfile
27+
networks:
28+
- 'stack'
29+
depends_on:
30+
- db
31+
environment:
32+
PG_CONNECTION_STRING: postgres://postgres:postgres@db:5432/postgres
33+
ports:
34+
- '4000:4000'
35+
healthcheck:
36+
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
37+
interval: 10s
38+
timeout: 5s
39+
retries: 5
40+
2241
networks:
2342
stack: {}

examples/hackernews/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"files": [
1010
"Dockerfile",
1111
"dist/src",
12+
"docker-compose.yml",
1213
"package.json",
13-
"prisma"
14+
"README.md"
1415
],
1516
"keywords": [],
1617
"scripts": {
1718
"build": "tsc",
1819
"check": "tsc --pretty --noEmit",
1920
"dev": "cross-env NODE_ENV=development node --loader=ts-node/esm --env-file .env --watch src/main.ts",
2021
"migrate": "pnpm drizzle-kit generate",
22+
"postbuild": "npx cpy 'src/**/*.{json,sql}' ./dist/src --parents",
2123
"start": "ts-node src/main.ts"
2224
},
2325
"dependencies": {
@@ -29,6 +31,7 @@
2931
"devDependencies": {
3032
"@types/node": "18.16.16",
3133
"@types/pg": "8.11.6",
34+
"cpy-cli": "5.0.0",
3235
"cross-env": "7.0.3",
3336
"drizzle-kit": "0.22.7",
3437
"ts-node": "10.9.1",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"scripts": {
3333
"build": "pnpm --filter=@graphql-yoga/graphiql run build && pnpm --filter=@graphql-yoga/render-graphiql run build && pnpm --filter=graphql-yoga run generate-graphiql-html && bob build",
3434
"build-website": "pnpm build && cd website && pnpm build",
35+
"build:hackernews:docker": "pnpm --filter=example-hackernews deploy --prod .hackernews-deploy",
3536
"changeset": "changeset",
3637
"check": "pnpm -r run check",
3738
"lint": "eslint --ignore-path .eslintignore --ext ts,js,tsx,jsx .",

pnpm-lock.yaml

Lines changed: 63 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)