From aa24e5ab0b1cf931a85b2bc53ed908b42729a0c6 Mon Sep 17 00:00:00 2001 From: Eugene Michkov Date: Mon, 6 May 2024 19:03:10 +0300 Subject: [PATCH] added ci --- .dockerignore | 4 ++ .github/workflows/publish-image.yml | 21 ++++++++++ Dockerfile | 23 +++++++++++ docker-compose.yml | 59 +++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/publish-image.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a97b5ec --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +target/ +LICENSE.md +README.md +.env \ No newline at end of file diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 0000000..8644cde --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,21 @@ +name: Docker Image CI for GHCR + +on: + push: + branches: + - production + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + run: echo "${{ secrets.GH_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Build the Docker image + run: docker build . -t ghcr.io/heliosshieldproject/${{ github.repository }}:${{ github.sha }} + + - name: Push the Docker image + run: docker push ghcr.io/heliosshieldproject/${{ github.repository }}:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f32e48 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM clux/muslrust:stable AS chef +ARG LOGGER_PORT +RUN cargo install cargo-chef +WORKDIR /logger + +FROM chef AS planner +COPY . . +CMD [ "mv", ".env.production", ".env" ] +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /logger/recipe.json recipe.json +RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json +COPY . . +CMD [ "mv", ".env.production", ".env" ] +RUN cargo build --release --target x86_64-unknown-linux-musl + +FROM scratch +LABEL org.opencontainers.image.source https://github.com/HeliosShieldProject/logger-rust +COPY --from=builder /logger/target/x86_64-unknown-linux-musl/release/logger /logger +COPY --from=builder /logger/.env.production .env +ENTRYPOINT ["/logger"] +EXPOSE $LOGGER_PORT \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3f12b56 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,59 @@ +name: "logger" + +services: + logger: + build: + context: . + args: + - LOGGER_PORT=${LOGGER_PORT} + dockerfile: Dockerfile + ports: + - "${LOGGER_PORT}:${LOGGER_PORT}" + env_file: + - .env.production + depends_on: + - logs-database + networks: + - logger-network + + logs-database: + image: mongo + restart: always + environment: + MONGO_INITDB_ROOT_USERNAME: ${LOGS_DATABASE_USER} + MONGO_INITDB_ROOT_PASSWORD: ${LOGS_DATABASE_PASSWORD} + volumes: + - logs-database-volume:/data/db + command: + - --port + - ${LOGS_DATABASE_PORT} + ports: + - "${LOGS_DATABASE_PORT}:${LOGS_DATABASE_PORT}" + env_file: + - .env.production + networks: + - logger-network + + logs-viewer: + image: mongo-express + restart: always + ports: + - ${LOGS_VIEWER_PORT}:8081 + environment: + ME_CONFIG_MONGODB_URL: ${MONGO_URL} + ME_CONFIG_OPTIONS_EDITORTHEME: nord + ME_CONFIG_BASICAUTH_USERNAME: ${LOGS_VIEWER_USER} + ME_CONFIG_BASICAUTH_PASSWORD: ${LOGS_VIEWER_PASSWORD} + env_file: + - .env.production + depends_on: + - logs-database + networks: + - logger-network + +volumes: + logs-database-volume: + +networks: + logger-network: + external: true