Skip to content

Commit

Permalink
build hackernews app docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jun 21, 2024
1 parent b71da2a commit 373efcf
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 8 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
cmd: yq -i 'del(.services.*.volumes)' examples/hackernews/docker-compose.yml

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

- name: Run Tests
uses: nick-fields/retry@v3
Expand Down Expand Up @@ -271,6 +271,30 @@ jobs:
failOnRequired: true
debug: true

hackernews-docker-container:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

- name: Setup env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 22
packageManager: pnpm

- name: Build Packages
run: pnpm build

- name: Build Hackernews App
run: pnpm --filter=example-hackernews build

- name: Isolate Docker Image Build Context
run: pnpm build:hackernews:docker

- name: Build Hackernews Docker Image
run: docker compose -f .hackernews-deploy/docker-compose.yml build api

# TODO: have the example and packages use singleton nestjs dependencies
# but without using .pnpmfile.cjs because it causes issues with renovate: https://github.com/dotansimha/graphql-yoga/pull/2622
# nestjs-apollo-federation-compatibility:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ packages/graphql-yoga/src/graphiql-html.ts
.tool-versions

.mise.toml
.hackernews-deploy
23 changes: 23 additions & 0 deletions examples/hackernews/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:22-slim

RUN apt-get update && apt-get install -y ca-certificates

WORKDIR /usr/src/app

COPY ./package.json /usr/src/app
COPY ./node_modules /usr/src/app/node_modules

COPY ./dist/src/ /usr/src/app/

LABEL org.opencontainers.image.title="Hackernews GraphQL Server"
LABEL org.opencontainers.image.version=$RELEASE
LABEL org.opencontainers.image.description="A Hackernews clone built with GraphQL and graphql-yoga."
LABEL org.opencontainers.image.authors="The Guild"
LABEL org.opencontainers.image.vendor="Laurin Quast"
LABEL org.opencontainers.image.url="https://github.com/dotansimha/graphql-yoga/tree/main/examples/hackernews"
LABEL org.opencontainers.image.source="https://github.com/dotansimha/graphql-yoga/tree/main/examples/hackernews"

ENV ENVIRONMENT production
ENV RELEASE $RELEASE

ENTRYPOINT ["node", "main.js"]
21 changes: 20 additions & 1 deletion examples/hackernews/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3.8'
services:
db:
postgres:
image: postgres:14.12-alpine
networks:
- 'stack'
Expand All @@ -19,5 +19,24 @@ services:
ports:
- '5432:5432'

api:
image: ${DOCKER_REGISTRY}yoga-hackernews${DOCKER_TAG}
build:
context: .
dockerfile: Dockerfile
networks:
- 'stack'
depends_on:
- db
environment:
PG_CONNECTION_STRING: postgres://postgres:postgres@db:5432/postgres
ports:
- '4000:4000'
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
interval: 10s
timeout: 5s
retries: 5

networks:
stack: {}
5 changes: 4 additions & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
"files": [
"Dockerfile",
"dist/src",
"docker-compose.yml",
"package.json",
"prisma"
"README.md"
],
"keywords": [],
"scripts": {
"build": "tsc",
"check": "tsc --pretty --noEmit",
"dev": "cross-env NODE_ENV=development node --loader=ts-node/esm --env-file .env --watch src/main.ts",
"migrate": "pnpm drizzle-kit generate",
"postbuild": "npx cpy 'src/**/*.{json,sql}' ./dist/src --parents",
"start": "ts-node src/main.ts"
},
"dependencies": {
Expand All @@ -29,6 +31,7 @@
"devDependencies": {
"@types/node": "18.16.16",
"@types/pg": "8.11.6",
"cpy-cli": "5.0.0",
"cross-env": "7.0.3",
"drizzle-kit": "0.22.7",
"ts-node": "10.9.1",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"scripts": {
"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",
"build-website": "pnpm build && cd website && pnpm build",
"build:hackernews:docker": "pnpm --filter=example-hackernews deploy --prod .hackernews-deploy",
"changeset": "changeset",
"check": "pnpm -r run check",
"lint": "eslint --ignore-path .eslintignore --ext ts,js,tsx,jsx .",
Expand Down
68 changes: 63 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 373efcf

Please sign in to comment.