From 3a0909e539f6b4ec5e156fe95c1065463b4f9a6a Mon Sep 17 00:00:00 2001 From: clragon Date: Sat, 2 Dec 2023 00:36:19 +0100 Subject: [PATCH] added container build --- .github/workflows/release.yml | 24 +++++++++++++++++++++- .gitignore | 4 +++- Dockerfile | 6 ++++++ README.md | 32 ++++++++++++++++++++++++++++++ lib/plugins/database/database.dart | 2 +- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d50d8f2..9002dd0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,6 +60,26 @@ jobs: name: app_${{ env.file_arch }} path: build/app_${{ env.file_arch }} + - name: build docker image + run: | + docker buildx create --name builder --use + docker buildx build \ + --platform ${{ matrix.arch }} \ + -t swan:${{ github.run_id }}-${{ env.file_arch }} \ + -t swan:latest \ + --build-arg ARCH=${{ matrix.arch }} \ + --build-arg BINARY=build/app_${{ env.file_arch }} \ + -f Dockerfile . \ + --output type=docker,dest=app_image_${{ env.file_arch }}.tar + env: + DOCKER_BUILDKIT: 1 + + - name: upload docker image artifact + uses: actions/upload-artifact@v3 + with: + name: app_image_${{ env.file_arch }} + path: app_image_${{ env.file_arch }}.tar + create-release: needs: build runs-on: ubuntu-latest @@ -76,6 +96,8 @@ jobs: uses: softprops/action-gh-release@v1 with: tag_name: release-${{ github.run_id }} - files: ./app_*/app_* + files: | + ./app_*/app_* + ./app_image_*/app_image_* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 7df90d9..a24af31 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ .vscode logs build -database.sqlite3 + +# app data +config/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..51654d9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +ARG ARCH +FROM --platform=$ARCH ubuntu +RUN apt-get update && apt-get install -y libsqlite3-dev +ARG BINARY +COPY $BINARY /app +ENTRYPOINT ["/app"] diff --git a/README.md b/README.md index a7cd73a..d70b27d 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,35 @@ You can also specify a custom prefix for the bot: ```yml BOT_PREFIX=your_prefix_here # default: . ``` + +## Docker + +You can run the bot in a Docker container. +A pre-built image is available in the releases section. + +To run your image, load the image: + +```sh +docker load -i app_image_*.tar +``` + +then create a docker compose file with the following content: + +```yml +version: "3.8" +services: + swan: + image: swan:latest + volumes: + - ./.env:/.env + - config:/config + +volumes: + config: +``` + +Then, run: + +```sh +docker compose up -d +``` diff --git a/lib/plugins/database/database.dart b/lib/plugins/database/database.dart index 2271e15..1ad8011 100644 --- a/lib/plugins/database/database.dart +++ b/lib/plugins/database/database.dart @@ -9,7 +9,7 @@ part 'database.g.dart'; class SwanDatabase extends _$SwanDatabase { SwanDatabase() : super( - NativeDatabase.createInBackground(File('database.sqlite3')), + NativeDatabase.createInBackground(File('config/database.sqlite3')), ); @override