Compare commits

...

2 Commits

Author SHA1 Message Date
6ca809b175 Merge branch 'main' of git.unom.io:moriese/avocadi-bot
Some checks failed
release-tag / release-image (push) Failing after 2m35s
2025-01-12 20:33:12 +01:00
f928b75678 add ci
containerize
2025-01-12 20:33:10 +01:00
5 changed files with 102 additions and 1 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -0,0 +1,49 @@
name: release-tag
on:
push
jobs:
release-image:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
# env:
# DOCKER_ORG: teacup
# DOCKER_LATEST: nightly
# RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: git.unom.io # replace it with your local IP
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Get Meta
id: meta
run: |
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: |
linux/amd64
linux/arm64
push: true
tags: | # replace it with your local IP and tags
git.unom.io/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
git.unom.io/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}

37
Dockerfile Normal file
View File

@ -0,0 +1,37 @@
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 AS base
WORKDIR /usr/src/app
# 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.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production
# 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 . .
# [optional] tests & build
ENV NODE_ENV=production
RUN bun test
#RUN bun run build
# 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/ .
# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ]

View File

@ -3,7 +3,8 @@
"module": "src/index.ts", "module": "src/index.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "bun --watch src/index.ts" "dev": "bun --watch src/index.ts",
"test": "bun test"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "^1.1.14", "@types/bun": "^1.1.14",

13
src/lib/utils.test.ts Normal file
View File

@ -0,0 +1,13 @@
import { describe, expect, it } from "bun:test";
import { getRandomInt } from "./utils.ts";
describe("utils", () => {
it("gets a random int", () => {
const randomInt = getRandomInt(0, 10);
expect(randomInt).toBeDefined();
expect(randomInt).toBeNumber();
expect(randomInt).toBeLessThanOrEqual(10);
expect(randomInt).toBeGreaterThanOrEqual(0);
});
});