From 8d20fe30721e1ee92afffb7ca0850296ae071d87 Mon Sep 17 00:00:00 2001 From: liuwen Date: Fri, 23 Aug 2024 09:39:32 +0800 Subject: [PATCH] Add Katbin as a submodule and integrate into package manager --- .github/workflows/katbin-build-push.yml | 45 +++++++++++++++++++++ .gitmodules | 3 ++ katbin/Dockerfile | 54 +++++++++++++++++++++++++ katbin/README.md | 25 ++++++++++++ katbin/source | 1 + 5 files changed, 128 insertions(+) create mode 100644 .github/workflows/katbin-build-push.yml create mode 100644 .gitmodules create mode 100644 katbin/Dockerfile create mode 100644 katbin/README.md create mode 160000 katbin/source diff --git a/.github/workflows/katbin-build-push.yml b/.github/workflows/katbin-build-push.yml new file mode 100644 index 0000000..a6f2eda --- /dev/null +++ b/.github/workflows/katbin-build-push.yml @@ -0,0 +1,45 @@ +name: Build and Push Katbin Docker Image + +on: + push: + branches: [ main ] + paths: + - 'katbin/**' + - '.github/workflows/katbin-build-push.yml' + pull_request: + branches: [ main ] + paths: + - 'katbin/**' + - '.github/workflows/katbin-build-push.yml' + workflow_dispatch: # Allow manual triggering + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: ./katbin + file: ./katbin/Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/katbin:latest + ghcr.io/${{ github.repository_owner }}/katbin:${{ github.sha }} diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..05b95e1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "katbin/source"] + path = katbin/source + url = https://github.com/SphericalKat/katbin diff --git a/katbin/Dockerfile b/katbin/Dockerfile new file mode 100644 index 0000000..03a1d6f --- /dev/null +++ b/katbin/Dockerfile @@ -0,0 +1,54 @@ +FROM elixir:alpine AS build + +# install build dependencies +RUN apk add --no-cache build-base npm git curl py-pip rust cargo + +# prepare build dir +WORKDIR /app + +# install hex + rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# set build ENV +ENV MIX_ENV=prod + +# install mix dependencies +COPY mix.exs mix.lock ./ +COPY config config +RUN mix do deps.get, deps.compile + +# build assets +COPY assets/package.json assets/package-lock.json ./assets/ +RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error + +COPY priv priv +COPY assets assets +COPY lib lib +COPY native native +RUN npm run --prefix ./assets deploy +RUN mix phx.digest + +# uncomment COPY if rel/ exists +# COPY rel rel +RUN mix do compile, release + +# prepare release image +FROM alpine AS app +RUN apk add --no-cache openssl ncurses-libs libstdc++ + +WORKDIR /app + +RUN chown nobody:nobody /app + +USER nobody:nobody + +COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/ketbin ./ + +COPY --chown=nobody:nobody startup.sh startup.sh + +RUN chmod +x /app/startup.sh + +ENV HOME=/app + +CMD ["/app/startup.sh"] diff --git a/katbin/README.md b/katbin/README.md new file mode 100644 index 0000000..95209b8 --- /dev/null +++ b/katbin/README.md @@ -0,0 +1,25 @@ +# Katbin + +This directory contains the configuration for Katbin, a pastebin service written in Kotlin, as part of the versatile package manager. + +## Features + +- Pastebin functionality +- Written in Kotlin +- Containerized for easy deployment + +## Files + +- `Dockerfile`: Defines the Katbin build and runtime environment +- `source/`: Git submodule containing the Katbin source code + +## Usage + +1. Ensure you've initialized and updated the git submodule: + ``` + git submodule update --init --recursive + ``` +2. Build the Docker image using the provided Dockerfile +3. Run the container, exposing port 8080 + +For more details on Katbin, please refer to the original project: [https://github.com/sphericalkat/katbin](https://github.com/sphericalkat/katbin) diff --git a/katbin/source b/katbin/source new file mode 160000 index 0000000..ebd9f7f --- /dev/null +++ b/katbin/source @@ -0,0 +1 @@ +Subproject commit ebd9f7f52c54c0a8487002e5bc8c73fce8fe63fb