Skip to content

Commit

Permalink
Merge pull request #40 from R-OV-NL/development
Browse files Browse the repository at this point in the history
Switch to bun and bugfix
  • Loading branch information
Arilith authored Feb 22, 2025
2 parents 847786c + 260c91b commit e7f1b30
Show file tree
Hide file tree
Showing 14 changed files with 1,449 additions and 177 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/deploy.yml

This file was deleted.

69 changes: 50 additions & 19 deletions .github/workflows/main_test.yml
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
13 changes: 3 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ on:

jobs:
build:
runs-on: ["self-hosted", "main"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
token: ${{ secrets.SHARED_PAT }}
submodules: recursive
- 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
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
run: docker compose -f docker-compose.test.yml up --force-recreate --abort-on-container-exit --exit-code-from app
55 changes: 36 additions & 19 deletions Dockerfile
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" ]
Loading

0 comments on commit e7f1b30

Please sign in to comment.