From 5af92693ee9e6142d7d57f48fdf8e1570c481337 Mon Sep 17 00:00:00 2001 From: proffapt Date: Mon, 1 Jul 2024 14:01:14 +0530 Subject: [PATCH] feat(cd): publish and pull from dockerhub --- .github/workflows/deploy.yaml | 75 +++++++++++++++++++++++++++++++--- docker-compose.yml | 4 +- mftp-doctor/README.md | 8 ++-- mftp-doctor/docker-compose.yml | 22 +++++----- mftp/README.md | 12 +++--- mftp/docker-compose.yml | 2 +- 6 files changed, 93 insertions(+), 30 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index d120321..c6c42fe 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -9,8 +9,73 @@ on: - "LICENSE" jobs: + dockerhub: + name: Publish Docker Image(s) to Dockerhub + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Cache Docker layers for MFTP Doctor + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache-mftp-doctor + key: ${{ runner.os }}-buildx-mftp-doctor-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-mftp-doctor- + + - name: Build & Push MFTP Doctor + uses: docker/build-push-action@v5 + with: + context: ./mftp-doctor/ + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/mftp-doctor:latest + cache-from: type=local,src=/tmp/.buildx-cache-mftp-doctor + cache-to: type=local,dest=/tmp/.buildx-cache-mftp-doctor-new,mode=max + + - name: Move MFTP Doctor cache + run: | + rm -rf /tmp/.buildx-cache-mftp-doctor + mv /tmp/.buildx-cache-mftp-doctor-new /tmp/.buildx-cache-mftp-doctor + + - name: Cache Docker layers for MFTP + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache-mftp + key: ${{ runner.os }}-buildx-mftp-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-mftp- + + - name: Build & Push MFTP + uses: docker/build-push-action@v5 + with: + context: ./mftp/ + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/mftp:latest + cache-from: type=local,src=/tmp/.buildx-cache-mftp + cache-to: type=local,dest=/tmp/.buildx-cache-mftp-new,mode=max + + - name: Move MFTP cache + run: | + rm -rf /tmp/.buildx-cache-mftp + mv /tmp/.buildx-cache-mftp-new /tmp/.buildx-cache-mftp + push: - name: Push Stage + name: Push Code Stage + needs: dockerhub runs-on: ubuntu-latest steps: @@ -30,13 +95,13 @@ jobs: sudo git fetch origin sudo git reset --hard origin/main - build: - name: Build Stage + pull: + name: Pull Image Stage needs: push runs-on: ubuntu-latest steps: - - name: Build the latest container(s) + - name: Pull the latest images(s) uses: appleboy/ssh-action@master env: PROJECT_DIR: ${{ secrets.PROJECT_DIR }} @@ -49,4 +114,4 @@ jobs: script_stop: true script: | cd "${PROJECT_DIR}/" - sudo docker compose --env-file .env build + sudo docker compose pull diff --git a/docker-compose.yml b/docker-compose.yml index dfd130e..359d9cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: build: context: ./mftp dockerfile: Dockerfile - image: proffapt/mftp + image: metakgporg/mftp container_name: mftp command: $MFTP_MODE volumes: @@ -22,7 +22,7 @@ services: build: context: ./mftp-doctor dockerfile: Dockerfile - image: proffapt/mftp-doctor + image: metakgporg/mftp-doctor container_name: mftp-doctor command: ${DOCTOR_MODE:-} volumes: diff --git a/mftp-doctor/README.md b/mftp-doctor/README.md index 4d86b82..629e906 100644 --- a/mftp-doctor/README.md +++ b/mftp-doctor/README.md @@ -46,7 +46,7 @@ The following requirements are to be satisfied for the project to function prope You can get the docker image from either docker-hub or by buiilding it locally: - Pull from docker-hub ```sh - sudo docker pull proffapt/mftp-doctor + sudo docker pull metakgporg/mftp-doctor ``` - Build from Dockerfile * Clone the repository and cd into it @@ -56,7 +56,7 @@ The following requirements are to be satisfied for the project to function prope ``` * Build the image ```sh - sudo docker build -t proffapt/mftp-doctor . + sudo docker build -t metakgporg/mftp-doctor . ``` 2. Create a directory which will contain your env.py, name it as `doctor_config` 3. Follow the steps to [configure env variables](#configuring-environment-variables) @@ -87,7 +87,7 @@ This container requires access to hosts' `docker.sock` to check logs of `mftp` c -v /var/run/docker.sock:/var/run/docker.sock \ -v /path/to/doctor_config/env.py:/mftp-doctor/env.py \ --name mftp-doctor \ - proffapt/mftp-doctor + metakgporg/mftp-doctor ```

(back to top)

@@ -107,7 +107,7 @@ It is also possible to run these docker containers as a cronjob: -v /var/run/docker.sock:/var/run/docker.sock \ -v /path/to/doctor_config/env.py:/mftp-doctor/env.py \ --name mftp-doctor \ - proffapt/mftp-doctor --cron + metakgporg/mftp-doctor --cron ``` - Add the updated command with desired [cron expression](https://crontab.cronhub.io/) into your cronjob using [crontab -e](https://www.man7.org/linux/man-pages/man5/crontab.5.html) diff --git a/mftp-doctor/docker-compose.yml b/mftp-doctor/docker-compose.yml index e8d27e2..d6744aa 100644 --- a/mftp-doctor/docker-compose.yml +++ b/mftp-doctor/docker-compose.yml @@ -1,15 +1,13 @@ - version: "3" services: - - mftp-doctor: - build: - context: . - dockerfile: Dockerfile - image: proffapt/mftp-doctor - container_name: mftp-doctor - command: ${DOCTOR_MODE:-} - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - $DOCTOR_CONFIG/env.py:/mftp-doctor/env.py + mftp-doctor: + build: + context: . + dockerfile: Dockerfile + image: metakgporg/mftp-doctor + container_name: mftp-doctor + command: ${DOCTOR_MODE:-} + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - $DOCTOR_CONFIG/env.py:/mftp-doctor/env.py diff --git a/mftp/README.md b/mftp/README.md index d5139ee..71e9ec7 100644 --- a/mftp/README.md +++ b/mftp/README.md @@ -47,7 +47,7 @@ The following requirements are to be satisfied for the project to function prope You can get the docker image from either docker-hub or by buiilding it locally: - Pull from docker-hub ```sh - sudo docker pull proffapt/mftp + sudo docker pull metakgporg/mftp ``` - Build from Dockerfile * Clone the repository and cd into it @@ -57,7 +57,7 @@ The following requirements are to be satisfied for the project to function prope ``` * Build the image ```sh - sudo docker build -t proffapt/mftp . + sudo docker build -t metakgporg/mftp . ``` 2. Create a directory which will contain your tokens and env.py, name it as `mftp_config` 3. Follow the steps to [configure mail sending](#sending-emails). **Skip this step if you wish to use method not involving mails, for example, ntfy** @@ -104,7 +104,7 @@ It is mandatory to provide either of the following flags to the execution comman -v /path/to/mftp_config/.session:/mftp/.session \ --restart=unless-stopped \ --name mftp \ - proffapt/mftp --smtp + metakgporg/mftp --smtp ``` - `--gmail-api`: Using Gmail API for sending mails @@ -119,7 +119,7 @@ It is mandatory to provide either of the following flags to the execution comman -v /path/to/mftp_config/.session:/mftp/.session \ --restart=unless-stopped \ --name mftp \ - proffapt/mftp --gmail-api + metakgporg/mftp --gmail-api ``` - `--ntfy`: Using NTFY to serve notification @@ -134,7 +134,7 @@ It is mandatory to provide either of the following flags to the execution comman -v /path/to/mftp_config/.session:/mftp/.session \ --restart=unless-stopped \ --name mftp \ - proffapt/mftp --ntfy + metakgporg/mftp --ntfy ```

(back to top)

@@ -169,7 +169,7 @@ It is also possible to run these docker containers as a cronjob: -v /path/to/mftp_config/.lsnif:/mftp/.lsnif \ -v /path/to/mftp_config/.session:/mftp/.session \ --name mftp \ - proffapt/mftp --gmail-api --cron + metakgporg/mftp --gmail-api --cron ``` - Add the updated command with desired [cron expression](https://crontab.cronhub.io/) into your cronjob using [crontab -e](https://www.man7.org/linux/man-pages/man5/crontab.5.html) diff --git a/mftp/docker-compose.yml b/mftp/docker-compose.yml index d46ed0c..9136806 100644 --- a/mftp/docker-compose.yml +++ b/mftp/docker-compose.yml @@ -7,7 +7,7 @@ services: build: context: . dockerfile: Dockerfile - image: proffapt/mftp + image: metakgporg/mftp container_name: mftp restart: unless-stopped command: $MFTP_MODE