-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from R-OV-NL/development
Switch to bun and bugfix
- Loading branch information
Showing
14 changed files
with
1,449 additions
and
177 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,67 @@ | ||
name: Test service on main | ||
name: Build, Test, and Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- 'main' | ||
|
||
workflow_dispatch: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ["self-hosted", "main"] | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
# Checkout the repository | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.SHARED_PAT }} | ||
submodules: recursive | ||
|
||
# Set up Docker | ||
- name: Set up Docker | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# Build the test stage of the Dockerfile | ||
- name: Rebuild Compose Images | ||
run: docker compose -f docker-compose.test.yml build --no-cache | ||
- name: Test image with Docker Compose | ||
run: docker compose -f docker-compose.test.yml up --force-recreate --abort-on-container-exit --exit-code-from app | ||
- name: Build and Push Docker Image | ||
uses: mr-smithers-excellent/docker-build-push@v5 | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
needs: build-and-test | ||
if: github.ref == 'refs/heads/main' | ||
|
||
steps: | ||
# Checkout the repository | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.SHARED_PAT }} | ||
submodules: recursive | ||
|
||
# Log in to DockerHub | ||
- name: Log in to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
image: arilith/r_ov | ||
registry: docker.io | ||
tags: gtfsrt | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
compose-down: | ||
runs-on: ["self-hosted", "main"] | ||
if: ${{ always() }} | ||
needs: [build] | ||
steps: | ||
- name: Docker compose down | ||
run: docker compose -f docker-compose.test.yml down | ||
|
||
# Build the release stage of the Dockerfile | ||
- name: Build and Push Docker Image | ||
run: | | ||
docker build --target release -t r_ov:gtfsrt . | ||
docker tag r_ov:gtfsrt arilith/r_ov:gtfsrt | ||
docker push arilith/r_ov:gtfsrt | ||
# Deploy the new Docker image by running the workflow in the Deploy repository | ||
- name: Deploy new Docker image | ||
uses: benc-uk/workflow-dispatch@v1 | ||
with: | ||
workflow: Deploy Docker Images of R-OV | ||
repo: R-OV-NL/Deploy | ||
token: ${{ secrets.SHARED_PAT }} | ||
ref: main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
FROM node:lts-alpine AS base | ||
# use the official Bun image | ||
# see all versions at https://hub.docker.com/r/oven/bun/tags | ||
FROM oven/bun:1.2 AS base | ||
WORKDIR /usr/src/app | ||
|
||
# Add a work directory | ||
WORKDIR /app | ||
# Cache and Install dependencies | ||
COPY package.json package.json | ||
COPY yarn.lock yarn.lock | ||
# install dependencies into temp directory | ||
# this will cache them and speed up future builds | ||
FROM base AS install | ||
RUN mkdir -p /temp/dev | ||
COPY package.json bun.lock /temp/dev/ | ||
RUN cd /temp/dev && bun install --frozen-lockfile | ||
|
||
RUN yarn global add ts-node typescript | ||
# install with --production (exclude devDependencies) | ||
RUN mkdir -p /temp/prod | ||
COPY package.json bun.lock /temp/prod/ | ||
RUN cd /temp/prod && bun install --frozen-lockfile --production | ||
|
||
FROM base as test | ||
RUN yarn install --pure-lock-file | ||
# Copy app files | ||
# copy node_modules from temp directory | ||
# then copy all (non-ignored) project files into the image | ||
FROM base AS prerelease | ||
COPY --from=install /temp/dev/node_modules node_modules | ||
COPY . . | ||
CMD ["yarn", "test"] | ||
|
||
FROM base as prod | ||
RUN yarn install --pure-lock-file --production | ||
# [optional] tests & build | ||
ENV NODE_ENV=production | ||
RUN bun test | ||
RUN bun run build | ||
|
||
FROM base AS test | ||
COPY --from=prerelease /usr/src/app/src src | ||
COPY --from=prerelease /usr/src/app/package.json . | ||
ENTRYPOINT [ "bun", "test" ] | ||
|
||
COPY . . | ||
|
||
RUN yarn add -D @types/node | ||
# Build the app | ||
RUN yarn build | ||
RUN yarn tsc | ||
# copy production dependencies and source code into final image | ||
FROM base AS release | ||
COPY --from=install /temp/prod/node_modules node_modules | ||
COPY --from=prerelease /usr/src/app/src src | ||
COPY --from=prerelease /usr/src/app/package.json . | ||
|
||
CMD ["yarn", "start"] | ||
# run the app | ||
USER bun | ||
EXPOSE 9393/tcp | ||
ENTRYPOINT [ "bun", "run", "src/main.ts" ] |
Oops, something went wrong.