diff options
author | Seth For Privacy <40500387+sethforprivacy@users.noreply.github.com> | 2024-04-23 10:06:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-23 14:06:15 +0000 |
commit | 91926dd2cd0a2008adbeb1b9fec12d84b8496204 (patch) | |
tree | 440d274b37fdd92aacf59ca5c7cd25591bb04731 | |
parent | 3c494018142b5a1c236681eb9a2abc9010ea1014 (diff) | |
download | sentrum-91926dd2cd0a2008adbeb1b9fec12d84b8496204.tar.gz sentrum-91926dd2cd0a2008adbeb1b9fec12d84b8496204.tar.bz2 sentrum-91926dd2cd0a2008adbeb1b9fec12d84b8496204.zip |
Add Dockerfile and GAs for Docker image deployment
* Initial Dockerfile and Github Actions
* Properly name final Docker build stage
* Add tag for package.version
* Correct cargo-get syntax
* Fix version tagging and add sentrum.toml to .gitignore
* Fix newlines and add Docker examples
* Fix branch on Github Action and minor copy update
-rw-r--r-- | .github/workflows/build-image-on-push.yml | 56 | ||||
-rw-r--r-- | .github/workflows/update-base-image.yml | 55 | ||||
-rw-r--r-- | .github/workflows/update-image-on-push.yml | 76 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Dockerfile | 20 | ||||
-rw-r--r-- | README.md | 47 |
6 files changed, 254 insertions, 1 deletions
diff --git a/.github/workflows/build-image-on-push.yml b/.github/workflows/build-image-on-push.yml new file mode 100644 index 0000000..2f02fb5 --- /dev/null +++ b/.github/workflows/build-image-on-push.yml @@ -0,0 +1,56 @@ +name: "Test build of image when Dockerfile is changed" + +on: + push: + paths: + - 'Dockerfile' + branches-ignore: + - master + pull_request: + paths: + - 'Dockerfile' + workflow_dispatch: + +jobs: + rebuild-container: + name: "Build image with cache" + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Build x86_64 image + id: docker_build_amd64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/amd64 + tags: sentrum:amd64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/sentrum:latest + - + name: Test-run x86_64 image + run: | + docker run --rm sentrum:amd64 & + PID=$! + sleep 5 + kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on + - + name: Build ARMv8 image + id: docker_build_arm64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/arm64 + tags: sentrum:arm64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/sentrum:latest diff --git a/.github/workflows/update-base-image.yml b/.github/workflows/update-base-image.yml new file mode 100644 index 0000000..5159808 --- /dev/null +++ b/.github/workflows/update-base-image.yml @@ -0,0 +1,55 @@ +name: "Update image and push to Github Packages and Docker Hub weekly" + +on: + schedule: + - cron: "0 12 * * 1" # Run every Monday at noon. + workflow_dispatch: + +jobs: + rebuild-container: + name: "Rebuild Container with the latest base image" + runs-on: ubuntu-latest + steps: + - + name: Prepare outputs + id: prep + run: | + echo "::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Get package version + id: cargo-get + uses: nicolaiunrein/cargo-get@master + with: + subcommand: package.version + - + name: Build and push to Docker Hub and GitHub Packages Docker Registry + id: docker_build + uses: docker/build-push-action@v5.3.0 + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository_owner }}/sentrum:latest + ghcr.io/${{ github.repository_owner }}/sentrum:${{ steps.cargo-get.outputs.metadata }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} diff --git a/.github/workflows/update-image-on-push.yml b/.github/workflows/update-image-on-push.yml new file mode 100644 index 0000000..b93a2f9 --- /dev/null +++ b/.github/workflows/update-image-on-push.yml @@ -0,0 +1,76 @@ +name: "Update image when Dockerfile is changed" + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + rebuild-container: + name: "Rebuild Container with the latest base image" + runs-on: ubuntu-latest + steps: + - + name: Prepare outputs + id: prep + run: | + echo "::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Get package version + id: cargo-get + uses: nicolaiunrein/cargo-get@master + with: + subcommand: package.version + - + name: Build x86_64 image + id: docker_build_amd64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/amd64 + tags: sentrum:amd64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/sentrum:latest + cache-to: type=inline + - + name: Test-run x86_64 image + run: | + docker run --rm sentrum:amd64 & + PID=$! + sleep 5 + kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on + - + name: Build and push to Docker Hub and GitHub Packages Docker Registry + uses: docker/build-push-action@v5.3.0 + id: docker_build_push + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository_owner }}/sentrum:latest + ghcr.io/${{ github.repository_owner }}/sentrum:${{ steps.cargo-get.outputs.metadata }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/sentrum:latest + cache-to: type=inline @@ -1 +1,2 @@ /target +sentrum.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e47c749 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM rust:bookworm as builder + +WORKDIR /usr/src/sentrum +COPY . . + +RUN cargo build --release + +FROM debian:bookworm-slim as final + +# Upgrade all packages and install dependencies +RUN apt-get update \ + && apt-get upgrade -y +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libssl-dev \ + && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +COPY --from=builder /usr/src/sentrum/target/release/sentrum /usr/local/bin/sentrum + +COPY sentrum.sample.toml sentrum.toml + +CMD ["sentrum"] @@ -346,7 +346,52 @@ sudo systemclt enable --now sentrum.service 6. Check the logs with `journalctl -fu sentrum` -# Future Work +## Docker + +To run sentrum using Docker, you can either build the image yourself or use the prebuilt image. + +### Building the image + +To build the image from source, run the following: + +```bash +git clone https://github.com/sommerfelddev/sentrum.git +cd sentrum +docker build -t sentrum:local . +``` + +To use the prebuilt image, simply pull from GHCR: + +```bash +docker pull docker pull ghcr.io/sommerfelddev/sentrum:latest +``` + +Note that there are two types of tags: + +`latest`: a tag from the latest commit to master +`x.x.x`: (i.e. `0.1.1`) a tag of the corresponding sentrum version + +### Running the image + +To run the image, simply run the following, passing in the `sentrum.toml` file you created and configured earlier: + +```bash +docker run --rm -it --volume ./sentrum.toml:/sentrum.toml ghcr.io/sommerfelddev/sentrum:latest +``` + +If using Docker compose, you can configure the service as follows: + +```yaml +services: + sentrum: + container_name: sentrum + image: ghcr.io/sommerfelddev/sentrum:latest + restart: unless-stopped + volumes: + - ./sentrum.toml:/sentrum.toml +``` + +## Future Work * More action types: - Matrix DM |