From b49e0cc64b732b7a0919e0a4f503b7f7d1d17a9b Mon Sep 17 00:00:00 2001 From: Lincoln Lee Date: Fri, 19 Jul 2024 03:59:06 +0000 Subject: [PATCH] feat: add deployment workflow --- .github/workflows/deploy.yml | 26 ++++++++++++++++++++++---- dinubot.service | 18 ++++++++++++++++++ docker-compose.yml | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 dinubot.service diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f0f515d1..be296997 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,17 +29,35 @@ jobs: with: push: true tags: nwplus/dinubot:latest + - + name: Upload systemd service file + uses: actions/upload-artifact@v3 + with: + name: dinubot-service-file + path: ./dinubot.service deploy: runs-on: self-hosted needs: dockerize steps: + - name: Download systemd service file + uses: actions/download-artifact@v3 + with: + name: dinubot-service-file + path: . + - name: Pull Docker image run: docker pull nwplus/dinubot:latest - - name: Run Docker container + - name: Copy systemd service file + run: sudo cp dinubot.service /etc/systemd/system/dinubot.service + + - name: Reload systemd daemon + run: sudo systemctl daemon-reload + + - name: Enable and start Dinubot service run: | - docker stop dinubot || true - docker rm dinubot || true - docker run -d -p 8000:8000 --name dinubot nwplus/dinubot:latest + sudo systemctl enable dinubot + sudo systemctl start dinubot + diff --git a/dinubot.service b/dinubot.service new file mode 100644 index 00000000..5b46c58f --- /dev/null +++ b/dinubot.service @@ -0,0 +1,18 @@ +[Unit] +Description=DinuBot, nwPlus's internal donut bot +After=network.target + +[Service] +Type=simple +User=ubuntu +Group=ubuntu +WorkingDirectory=/home/ubuntu/DinuBot +ExecStart=/usr/bin/docker compose up +ExecStop=/usr/bin/docker compose down +Restart=always + +[Install] +WantedBy=multi-user.target + +[Service] +Restart=always diff --git a/docker-compose.yml b/docker-compose.yml index 70f242a9..ea4cacee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: dinubot: - image: lsha0730/dinubot + image: nwplus/dinubot build: . env_file: - .env