Skip to content

Commit

Permalink
Merge branch 'main' into chore-update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwade committed Aug 6, 2024
2 parents 723f07c + ff4539b commit 328a66a
Show file tree
Hide file tree
Showing 81 changed files with 3,844 additions and 1,405 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/load-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Load Tests

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
determine-service-matrix:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.determine-matrix.outputs.changes }}
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: determine-matrix
with:
# Note, 'common' is for future use--when code is factored out into common libraries,
# but it's set up here so that the workflow logic could be tested with it present
filters: |
common:
- '*'
- '.github/**'
account:
- '*'
- '.github/**'
- 'services/account/**'
graph:
- '*'
- '.github/**'
- 'services/graph/**'
content-publishing:
- '*'
- '.github/**'
- 'services/content-publishing/**'
content-watcher:
- '*'
- '.github/**'
- 'services/content-watcher/**'
build:
name: '[${{ matrix.service }}] Load Test'
runs-on: ubuntu-latest
needs: determine-service-matrix
strategy:
fail-fast: false
matrix:
service: ${{ fromJson(needs.determine-service-matrix.outputs.services) }}
exclude:
- service: common
steps:
- uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
cache-dependency-path: tools/ci-k6/package-lock.json
- name: Install dependencies
working-directory: tools/ci-k6
run: npm ci

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}

- name: Start Frequency
run: |
docker compose -f docker-compose.yaml -f docker-compose-k6.${{ matrix.service }}.yaml up -d frequency
sleep 5
- name: Generate Provider and Capacity
working-directory: tools/ci-k6
run: npm run main

# Just start the services we need...
- name: Start All Services
run: docker compose -f docker-compose.yaml -f docker-compose-k6.${{ matrix.service }}.yaml up -d

- name: Wait for API to be ready
uses: cygnetdigital/[email protected]
with:
url: 'http://localhost:3000/readyz'
responseCode: '200'
timeout: 120000
interval: 2000

- name: Setup K6
uses: grafana/setup-k6-action@v1
- name: Run k6 Tests
run: |
for test_file in services/${{ matrix.service }}/k6-test/*.k6.js; do
k6 run --no-color --quiet --no-usage-report "$test_file" || exit 1
done
- name: Stop Docker Compose
if: always()
run: docker compose -f docker-compose.yaml -f docker-compose-k6.${{ matrix.service }}.yaml down
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Release"
run-name: "Cut Release ${{ github.event.release.tag_name || github.event.inputs.release-tag}}"
name: 'Release'
run-name: 'Cut Release ${{ github.event.release.tag_name || github.event.inputs.release-tag}}'
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
Expand All @@ -9,12 +9,12 @@ on:
workflow_dispatch:
inputs:
release-tag:
description: "Release tag ([servicename-]v#.#.#[-rc#])"
description: 'Release tag ([servicename-]v#.#.#[-rc#])'
required: true

env:
FULL_TAG: ${{ github.event.release.tag_name || github.event.inputs.release-tag}}
DOCKER_HUB_PROFILE: amplicalabs
DOCKER_HUB_PROFILE: projectlibertylabs
ALL_SERVICES: '["account", "content-publishing", "content-watcher", "graph"]'

jobs:
Expand All @@ -33,7 +33,7 @@ jobs:
run: |
valid=false
test_run=false
ENTIRE_TAG_RE="^(([[:alpha:]]+)-)?(.*)$"
ENTIRE_TAG_RE="^(([[:alpha:]\-]+)-)?(.*)$"
VERSION_TAG_RE="^v[\.]?([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-[[:alpha:][:digit:]\.]+)*)$"
TAG="${{ github.event.release.tag_name }}"
echo "Running with tag: ${TAG}"
Expand Down Expand Up @@ -107,13 +107,13 @@ jobs:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_USERNAME_FC}}
password: ${{secrets.DOCKERHUB_TOKEN_FC}}
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
- name: Build and Push account-service-service Image
uses: docker/build-push-action@v5
with:
context: services/${{ matrix.service }}
context: .
platforms: linux/amd64
push: ${{ needs.set_variables.outputs.test_run != 'true'}}
file: services/account/Dockerfile
file: Docker/Dockerfile.${{ matrix.service }}
tags: ${{ steps.cp-tags.outputs.tags }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ web_modules/
.yarn-integrity

# dotenv environment variable files
.env
.env*
.env.*

# parcel-bundler cache (https://parceljs.org/)
Expand Down
27 changes: 17 additions & 10 deletions services/account/Dockerfile → Docker/Dockerfile.account
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
# Use a multi-stage build for efficiency
FROM node:20 AS builder

WORKDIR /app
WORKDIR /build/packages

COPY packages ./

WORKDIR /build/services/account

COPY package*.json ./
COPY services/account/package* ./

RUN npm ci

COPY . .
COPY services/account ./

# Build the application
RUN npm run build
RUN npm run build && \
rm -rf node_modules && \
npm ci --omit=dev

# Production stage
FROM node:20

ENV NODE_ENV=production

WORKDIR /app

COPY --from=builder /app/dist ./dist
COPY package*.json ./
COPY ./lua ./lua
COPY ./scripts/docker-entrypoint.sh ./
COPY --from=builder /build/services/account/dist ./dist/
COPY services/account/package*.json ./
COPY services/account/lua ./lua/
COPY services/account/scripts/docker-entrypoint.sh ./
COPY --from=builder /build/services/account/node_modules ./node_modules/
RUN chmod +x ./docker-entrypoint.sh

RUN npm ci --omit=dev

# We want jq and curl in the final image, but we don't need the support files
RUN apt-get update && \
apt-get install -y jq curl tini && \
Expand Down
45 changes: 45 additions & 0 deletions Docker/Dockerfile.content-publishing
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Use a multi-stage build for efficiency
FROM node:20 AS builder

WORKDIR /build/packages

COPY packages ./

WORKDIR /build/services/content-publishing

COPY services/content-publishing/package* ./

RUN npm ci

COPY services/content-publishing ./

# Build the application
RUN npm run build && \
rm -rf node_modules && \
npm ci --omit=dev

# Production stage
FROM node:20

ENV NODE_ENV=production

WORKDIR /app

COPY --from=builder /build/services/content-publishing/dist ./dist/
COPY services/content-publishing/package*.json ./
COPY services/content-publishing/lua ./lua/
COPY services/content-publishing/scripts/docker-entrypoint.sh ./
COPY --from=builder /build/services/content-publishing/node_modules ./node_modules/
RUN chmod +x ./docker-entrypoint.sh

# We want jq and curl in the final image, but we don't need the support files
RUN apt-get update && \
apt-get install -y jq curl tini && \
apt-get clean && \
rm -rf /usr/share/doc /usr/share/man /usr/share/zsh

EXPOSE 3000

ENV START_PROCESS="api"

ENTRYPOINT ["/usr/bin/tini", "--", "./docker-entrypoint.sh"]
40 changes: 40 additions & 0 deletions Docker/Dockerfile.content-watcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Use a multi-stage build for efficiency
FROM node:20 AS builder

WORKDIR /build/packages

COPY packages ./

WORKDIR /build/services/content-watcher

COPY services/content-watcher/package* ./

RUN npm ci

COPY services/content-watcher ./

# Build the application
RUN npm run build && \
rm -rf node_modules && \
npm ci --omit=dev

# Production stage
FROM node:20

ENV NODE_ENV=production

WORKDIR /app

COPY --from=builder /build/services/content-watcher/dist ./dist/
COPY services/content-watcher/package*.json ./
COPY --from=builder /build/services/content-watcher/node_modules ./node_modules/

# We want jq and curl in the final image, but we don't need the support files
RUN apt-get update && \
apt-get install -y jq curl tini && \
apt-get clean && \
rm -rf /usr/share/doc /usr/share/man /usr/share/zsh

EXPOSE 3000

ENTRYPOINT [ "/usr/bin/tini", "--", "node", "dist/apps/api/main.js" ]
7 changes: 7 additions & 0 deletions Docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:20

WORKDIR /app

EXPOSE 3000

VOLUME [ "/app", "/app/services/account/node_modules", "/app/services/graph/node_modules", "/app/services/content-publishing/node_modules", "/app/services/content-watcher/node_modules" ]
45 changes: 45 additions & 0 deletions Docker/Dockerfile.graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Use a multi-stage build for efficiency
FROM node:20 AS builder

WORKDIR /build/packages

COPY packages ./

WORKDIR /build/services/graph

COPY services/graph/package* ./

RUN npm ci

COPY services/graph ./

# Build the application
RUN npm run build && \
rm -rf node_modules && \
npm ci --omit=dev

# Production stage
FROM node:20

ENV NODE_ENV=production

WORKDIR /app

COPY --from=builder /build/services/graph/dist ./dist/
COPY services/graph/package*.json ./
COPY services/graph/lua ./lua/
COPY services/graph/scripts/docker-entrypoint.sh ./
COPY --from=builder /build/services/graph/node_modules ./node_modules/
RUN chmod +x ./docker-entrypoint.sh

# We want jq and curl in the final image, but we don't need the support files
RUN apt-get update && \
apt-get install -y jq curl tini && \
apt-get clean && \
rm -rf /usr/share/doc /usr/share/man /usr/share/zsh

EXPOSE 3000

ENV START_PROCESS="api"

ENTRYPOINT ["/usr/bin/tini", "--", "./docker-entrypoint.sh", "prod"]
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,27 @@ $(FORMAT_TARGETS):
@( cd services/$(@:format-%=%) ; npm run format )

$(DOCKER_BUILD_TARGETS):
@( cd services/$(@:docker-build-%=%) ; npm run docker:build )
@docker build -t $(@:docker-build-%=%)-service -f Docker/Dockerfile.$(@:docker-build-%=%) .

docker-build: $(DOCKER_BUILD_TARGETS)

start-account-api:
@( cd services/account ; npm i ; npm run start:api:watch )

start-account-worker:
@( cd services/account ; npm i ; npm run start:worker:watch )

start-content-publishing-api:
@( cd services/content-publishing ; npm i ; npm run start:api:watch )

start-content-publishing-worker:
@( cd services/content-publishing ; npm i ; npm run start:worker:watch )

start-content-watcher:
@( cd services/content-watcher ; npm i ; npm run start:watch )

start-graph-api:
@( cd services/graph ; npm i ; npm run start:api:watch )

start-graph-worker:
@( cd services/graph ; npm i ; npm run start:worker:watch )
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ Clone:
To run all Gateway services, execute the following command:

```sh
docker compose docker-compose.all.yaml
./start-gateway.sh
```

To stop the Gateway services, execute the following command:

```sh
./stop-gateway.sh
```

To build the Gateway Documentation:
Expand Down
Loading

0 comments on commit 328a66a

Please sign in to comment.