Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: monorepo layout #118

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
versioning-strategy: increase
schedule:
interval: "daily"
time: "09:00"
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: [main]

jobs:
build:
build-stats:
runs-on: ubuntu-latest
services:
postgres:
Expand All @@ -24,6 +24,7 @@ jobs:
--health-retries 5
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
NPM_CONFIG_WORKSPACE: stats
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -33,6 +34,16 @@ jobs:
- run: npm run migrate
- run: npm test

lint-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint

docker-build:
runs-on: ubuntu-latest
permissions:
Expand All @@ -49,7 +60,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
- name: Build monorepo Docker image
uses: docker/build-push-action@v5
with:
context: .
Expand All @@ -58,12 +69,12 @@ jobs:

deploy:
if: github.ref == 'refs/heads/main'
needs: [build, docker-build]
needs: [build-stats, docker-build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
- run: flyctl deploy --remote-only -c stats/fly.toml
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- if: failure()
Expand Down
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ WORKDIR /app
# Set production environment
ENV NODE_ENV production
ENV SENTRY_ENVIRONMENT production
ENV REQUEST_LOGGING false

#######################################################################
# Throw-away build stage to reduce size of final image
Expand All @@ -27,7 +26,12 @@ RUN apt-get update -qq && \
# to install all modules: "npm install --production=false".
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
COPY --link package-lock.json package.json ./
RUN npm ci

# We cannot use a wildcard until `COPY --parents` is stabilised
# See https://docs.docker.com/reference/dockerfile/#copy---parents
COPY --link stats/package.json ./stats/

RUN npm ci --workspaces

# Copy application code
COPY --link . .
Expand All @@ -39,5 +43,8 @@ FROM base
# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]
# Set to `publish` or `api`
# This argument controls the value passed to npm start --workspace parameter
ENV SERVICE=""

CMD npm start --workspace ${SERVICE}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ npm test
### Run the service

```sh
npm start
npm start --workspace stats
```

You can also run the service against live data in Spark DB running on Fly.io.
Expand Down
Loading