From ab7f75b416c5d2777074c1e2efa4ea553b062bad Mon Sep 17 00:00:00 2001 From: David Date: Thu, 29 Dec 2022 22:15:49 +0100 Subject: [PATCH] Modified ci/cd to push dockerfile to dockerhub --- .gitlab-ci.yml | 67 ++++++++++++++++++++------------------------------ Cargo.toml | 4 +-- Dockerfile | 15 ++++++----- README.md | 9 +++++++ 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d8a6e4c..61af5ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,49 +1,34 @@ -# This file is a template, and might need editing before it works on your project. -# You can copy and paste this template into a new `.gitlab-ci.yml` file. -# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. -# -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/ee/development/cicd/templates.html -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Rust.gitlab-ci.yml +.caching_rust: &caching_rust + cache: + paths: + - .cargo/ + - .cache/sccache + - target/x86_64-unknown-linux-musl/release/material -# Official language image. Look for the different tagged releases at: -# https://hub.docker.com/r/library/rust/tags/ -image: "rust:latest" +stages: + - test + - build -# Optional: Pick zero or more services to be used on all builds. -# Only needed when using a docker container to run your tests in. -# Check out: https://docs.gitlab.com/ee/ci/services/index.html -# services: -# - mysql:latest -# - redis:latest -# - postgres:latest - -# Optional: Install a C compiler, cmake and git into the container. -# You will often need this when you (or any of your dependencies) depends on C code. -# before_script: -# - apt-get update -yqq -# - apt-get install -yqq --no-install-recommends build-essential - -# Use cargo to test the project -test:cargo: +run_tests_cargo: + stage: test + image: "rust:latest" + # Use cargo to test the project script: - rustc --version && cargo --version # Print version info for debugging - cargo build - cargo test --workspace --verbose -# Optional: Use a third party library to generate gitlab junit reports -# test:junit-report: -# script: -# Should be specified in Cargo.toml -# - cargo install junitify -# - cargo test -- --format=json -Z unstable-options --report-time | junitify --out $CI_PROJECT_DIR/tests/ -# artifacts: -# when: always -# reports: -# junit: $CI_PROJECT_DIR/tests/*.xml +docker-build-main: + # Official docker image. + image: "docker:latest" + stage: build + services: + - docker:dind + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE" . + - docker push "$CI_REGISTRY_IMAGE:latest" + only: + - main -# deploy: -# stage: deploy -# script: echo "Define your deployment script!" -# environment: production diff --git a/Cargo.toml b/Cargo.toml index 6a53199..d3b2058 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "matrix-modbot" -authors = ["David Dai https://www.gitlab.com/david-0609"] +authors = ["David (Peiran) Dai https://www.gitlab.com/david-0609"] version = "0.1.0" -edition = "2021" +edition="2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/Dockerfile b/Dockerfile index 37c4add..1028d57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,12 @@ -# syntax=docker/dockerfile:1 +# # syntax=docker/dockerfile:1 FROM rust:latest as builder +WORKDIR /usr/src/matrix-modbot COPY . . RUN cargo build --release -RUN cargo run +RUN cargo install --path . -FROM rust:latest -COPY --from=builder /target /target -COPY --from=builder config.ini config.ini -WORKDIR /target -RUN ./matrix-modbot config.ini +FROM debian:stable-slim +COPY --from=builder /usr/local/cargo/bin/matrix-modbot /usr/local/bin/matrix-modbot +RUN touch config.ini +CMD ["matrix-modbot", "config.ini"] HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 CMD curl --fail http://localhost:5000/health || exit 1 - diff --git a/README.md b/README.md index d8a8ec5..c60283b 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,12 @@ Matrix Modbot is a bot for Matrix used to automatically moderate Matrix rooms. ## Who is this bot for? The bot is orientated towards admins of large Matrix rooms that are public and require moderation. With this bot, simple jobs such as swear filtering and spam prevention could be accomplished without intervention of human moderators. + +## How to run? + +**Using Docker:** + docker run -v /local/path/to/config.int:/config.ini -t matrix-modbot:latest + +**Using Cargo:** + cargo build --release + cargo run