Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
79 changes: 79 additions & 0 deletions .github/disabled_workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Archived: For custom deployment
name: Dockerize and Deploy

on:
push:
branches:
- main
workflow_dispatch:

jobs:
dockerize:
runs-on: ubuntu-latest
steps:
- name: Checkout code
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_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: nwplus/factotum:latest
- name: Upload systemd service file
uses: actions/upload-artifact@v4
with:
name: factotum-service-file
path: ./factotum.service
- name: Upload docker-compose file
uses: actions/upload-artifact@v4
with:
name: factotum-docker-compose
path: ./docker-compose.yml

deploy:
runs-on: self-hosted
needs: dockerize

steps:
- name: Pull Docker image
run: docker pull nwplus/factotum:latest

- name: Download systemd service file
uses: actions/download-artifact@v4
with:
name: factotum-service-file
path: .

- name: Download docker-compose file
uses: actions/download-artifact@v4
with:
name: factotum-docker-compose
path: .

- name: Copy systemd service file
run: sudo cp factotum.service /etc/systemd/system/factotum.service

- name: Create .env file from secret
run: echo '${{ secrets.ENV_FILE }}' > .env

- name: Create service_account.json file from secret
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json

- name: Reload systemd daemon
run: sudo systemctl daemon-reload

- name: Stop existing Factotum service
run: sudo systemctl stop factotum

- name: Enable and start Factotum service
run: |
sudo systemctl enable factotum
sudo systemctl start factotum
16 changes: 16 additions & 0 deletions .github/disabled_workflows/refresh_secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Archived: For custom deployment
name: Refresh Secrets on Server

on:
workflow_dispatch:

jobs:
restart-service:
runs-on: self-hosted
steps:
- name: Create .env file from secret
run: echo '${{ secrets.ENV_FILE }}' > .env

- name: Restart Factotum service
run: |
sudo systemctl restart factotum
33 changes: 33 additions & 0 deletions .github/workflows/server_dockerhub_push_onmerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and push to Docker Hub on merge

on:
push:
branches: [main]
workflow_dispatch:

jobs:
build_and_push:
runs-on: ubuntu-latest
env:
IMAGE_NAME: nwplus/factotum:latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE_NAME }}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:20-alpine

USER node

WORKDIR /app

COPY package*.json ./

RUN yarn install

COPY . .

ENV NAME=factotum

ENV NODE_ENV=PROD

CMD ["node", "app.js"]
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
factotum:
image: nwplus/factotum
build: .
env_file:
- .env
volumes:
- ./.env:/app/.env:ro
18 changes: 18 additions & 0 deletions factotum.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=The do-it-all hackathon Discord bot.
After=network.target

[Service]
Type=simple
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/actions-runner/_work/Factotum/Factotum
ExecStart=/usr/bin/docker compose up
ExecStop=/usr/bin/docker compose down
Restart=always

[Install]
WantedBy=multi-user.target

[Service]
Restart=always
Loading