Skip to content

Commit

Permalink
feat: cleanup api (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored Oct 24, 2023
1 parent c092672 commit 50bd83c
Show file tree
Hide file tree
Showing 29 changed files with 442 additions and 283 deletions.
44 changes: 13 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Release

on:
pull_request:
branches:
- main
push:
branches:
- main
Expand Down Expand Up @@ -34,31 +37,25 @@ jobs:
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- name: Build
- name: Build client
working-directory: packages/client/
run: pnpm build

- name: Build server
working-directory: packages/server/
run: pnpm build

- name: Build the Docker image
run: docker build --file packages/server/Containerfile --tag $IMAGE_NAME:latest --cache-from ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest .

- name: Login to DockerHub registry
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
run: docker build --tag $IMAGE_NAME:latest --cache-from ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest .

- name: Log in to Github registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push image to DockerHub (latest & tag)
run: |
docker tag $IMAGE_NAME:latest ${{ env.DOCKERHUB_ORG }}/$IMAGE_NAME:latest
docker push ${{ env.DOCKERHUB_ORG }}/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest ${{ env.DOCKERHUB_ORG }}/$IMAGE_NAME:${GITHUB_REF#refs/*/}
docker push ${{ env.DOCKERHUB_ORG }}/$IMAGE_NAME:${GITHUB_REF#refs/*/}
if: "github.ref_type == 'tag'"
if: github.event_name != 'pull_request'

- name: Push image to Github registry (latest & tag)
run: |
Expand All @@ -68,17 +65,11 @@ jobs:
docker push ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:${GITHUB_REF#refs/*/}
if: "github.ref_type == 'tag'"

- name: Push image to DockerHub (next)
run: |
docker tag $IMAGE_NAME:latest ${{ env.DOCKERHUB_ORG }}/$IMAGE_NAME:next
docker push ${{ env.DOCKERHUB_ORG }}/$IMAGE_NAME:next
if: "github.ref_type != 'tag'"

- name: Push image to Github registry (next)
run: |
docker tag $IMAGE_NAME:latest ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:next
docker push ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:next
if: "github.ref_type != 'tag'"
if: github.event_name != 'pull_request' && github.ref_type != 'tag'

client:
name: Release client
Expand Down Expand Up @@ -108,7 +99,7 @@ jobs:
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true
Expand All @@ -133,15 +124,6 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: "github.ref_type == 'tag'"

# - name: Release pre version
# working-directory: packages/client/
# run: |
# pnpm version 1.0.0-pre.1 --no-commit-hooks --no-git-tag-version
# pnpm publish --no-git-check --access public --tag pre
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# if: "github.ref_type != 'tag'"

- name: Deploy 🚀
uses: JamesIves/[email protected]
with:
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true
Expand Down Expand Up @@ -60,13 +60,14 @@ jobs:
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- name: Build
run: pnpm run -r build
- name: Build client
working-directory: packages/client/
run: pnpm build

- name: Typecheck
run: pnpm run -r typecheck
Expand All @@ -93,14 +94,15 @@ jobs:
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

# needed to prepare the auto-generated files for the client package
- name: Build
run: pnpm run -r build
- name: Build client
working-directory: packages/client/
run: pnpm build

- name: Lint
run: pnpm run -r lint
Expand All @@ -127,10 +129,10 @@ jobs:
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- name: Check format
run: pnpm run lint:format
run: pnpm run format:check
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:18-alpine as overmind
WORKDIR /app
RUN apk add --update curl gzip
RUN curl https://github.com/DarthSim/overmind/releases/download/v2.4.0/overmind-v2.4.0-linux-amd64.gz -L -o overmind.gz
RUN gunzip overmind.gz
RUN chmod +x overmind

FROM node:18-alpine
ENV NODE_ENV=production
ENV DATA_PATH=/app/data
RUN apk --no-cache add ca-certificates tmux
EXPOSE 7171
WORKDIR /app
CMD ["overmind", "start"]
COPY Procfile .
COPY --from=overmind /app/overmind /bin/overmind

# server
COPY ./packages/server/dist/ .
COPY ./packages/server/public/ ./public
COPY ./packages/server/templates/ ./templates

# TODO: used to suppress warning remove after fixed
RUN mkdir -p /static

RUN chown -R node:node /app
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api: PORT=7171 node --enable-source-maps index.js
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"license": "MIT",
"repository": "github:geprog/gringotts",
"scripts": {
"lint:format": "prettier --check .",
"format:check": "prettier --check .",
"format:fix": "prettier --write .",
"start": "pnpm --parallel start"
},
"devDependencies": {
Expand Down
17 changes: 0 additions & 17 deletions packages/server/Containerfile

This file was deleted.

4 changes: 2 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"generate-swagger-spec": "tsx cli/generate-swagger-spec.ts"
},
"dependencies": {
"@fastify/cors": "^8.3.0",
"@fastify/formbody": "^7.0.1",
"@fastify/helmet": "^9.1.0",
"@fastify/static": "^6.5.0",
"@fastify/static": "^6.11.2",
"@fastify/swagger": "^7.4.1",
"@fastify/view": "^7.1.0",
"@mikro-orm/core": "^5.6.11",
Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/api/endpoints/customer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Customer endpoints', () => {
headers: {
authorization: `Bearer ${testData.project.apiToken}`,
},
url: '/customer',
url: '/api/customer',
payload: customerData,
});

Expand Down Expand Up @@ -106,7 +106,7 @@ describe('Customer endpoints', () => {
// when
const customersResponse = await server.inject({
method: 'GET',
url: `/customer`,
url: `/api/customer`,
headers: {
authorization: `Bearer ${testData.project.apiToken}`,
},
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('Customer endpoints', () => {
// when
const customersResponse = await server.inject({
method: 'GET',
url: `/customer`,
url: `/api/customer`,
headers: {
authorization: `Bearer ${testData.project.apiToken}`,
},
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('Customer endpoints', () => {
// when
const customerResponse = await server.inject({
method: 'GET',
url: `/customer/${testData.customer._id}`,
url: `/api/customer/${testData.customer._id}`,
headers: {
authorization: `Bearer ${testData.project.apiToken}`,
},
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('Customer endpoints', () => {
headers: {
authorization: `Bearer ${testData.project.apiToken}`,
},
url: `/customer/${customerData._id}`,
url: `/api/customer/${customerData._id}`,
payload: customerData,
});

Expand Down Expand Up @@ -304,7 +304,7 @@ describe('Customer endpoints', () => {
headers: {
authorization: `Bearer ${testData.project.apiToken}`,
},
url: `/customer/${customerData._id}`,
url: `/api/customer/${customerData._id}`,
});

// then
Expand Down
Loading

0 comments on commit 50bd83c

Please sign in to comment.