Skip to content

Commit

Permalink
Merge pull request #72 from ist-bot-team/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia authored Oct 3, 2022
2 parents 46a6314 + 0f34e2b commit c7b9ab6
Show file tree
Hide file tree
Showing 58 changed files with 8,020 additions and 726 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
data/
dist/
.husky/
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "varsIgnorePattern": "^_" }
]
}
}
53 changes: 53 additions & 0 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Create and publish a Docker image

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
.env
.venv
node_modules/
dist/
data/
docker-compose.yml

.vscode

shell.nix
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 4,
"useTabs": true
}
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:16.17.0-alpine3.16 as ts-compiler
ARG DATABASE_URL
ENV DATABASE_URL ${DATABASE_URL}
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install --frozen-lockfile
COPY ./ ./
RUN yarn run prisma generate
RUN yarn build

FROM node:16.17.0-alpine3.16
ARG DATABASE_URL
ENV DATABASE_URL ${DATABASE_URL}
WORKDIR /app
COPY --from=ts-compiler /app/package.json .
COPY --from=ts-compiler /app/yarn.lock .
COPY --from=ts-compiler /app/src/prisma ./src/prisma
COPY --from=ts-compiler /app/dist ./dist
RUN yarn install --prod --frozen-lockfile
RUN yarn run prisma generate
CMD [ "yarn", "start:docker" ]
11 changes: 11 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:16.17.0-alpine3.16
ARG DATABASE_URL
ENV DATABASE_URL ${DATABASE_URL}
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install --frozen-lockfile
COPY ./ ./
RUN yarn run prisma generate
RUN yarn build
CMD [ "yarn", "start:docker:dev" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 IST Bot Team
Copyright (c) 2021 IST Bot Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
# ist-discord-bot
# IST Discord Bot

![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/ist-bot-team/ist-discord-bot?label=version)
[![Discord](https://img.shields.io/discord/759576132227694642?label=discord&logo=discord)](https://discord.leic.pt)
![GitHub](https://img.shields.io/github/license/ist-bot-team/ist-discord-bot)

Discord bot to manage the IST Hub server -- join [here](https://discord.leic.pt).

### Running

#### Production

1. Create a `docker-compose.yml` file as below:

```yaml
version: "3.8"

services:
ist-discord-bot:
## EITHER:
image: ghcr.io/ist-bot-team/ist-discord-bot:2
## OR:
build:
context: .
dockerfile: Dockerfile.dev
args:
DATABASE_URL: file:/app/data/bot.db
## END;
volumes:
- type: bind
source: ./data
target: /app/data
environment:
DISCORD_TOKEN: PLACE_BOT_TOKEN_HERE
GUILD_ID: PLACE_MAIN_GUILD_ID_HERE # or "GLOBAL" to use in multiple guilds (1hr roll-out time)
ADMIN_ID: PLACE_ADMIN_ROLE_ID_HERE
ADMIN_PLUS_ID: PLACE_ADMIN_PLUS_ROLE_ID_HERE
COMMAND_LOGS_CHANNEL_ID: PLACE_LOGGING_CHANNEL_ID_HERE
TZ: Europe/Lisbon # default timezone for crontab and other date related stuff
restart: unless-stopped
```
2. Create a folder named `data` for Docker to store things in
3. Run `docker-compose up -d --build`
4. That's it!

_You can also use `docker-compose down`, `docker-compose up`, `docker-compose restart` and `docker-compose logs [-f]`._

### Adding to a Server

Replacing `CLIENT_ID` with the application's public ID, access the following link:

```
https://discord.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot+applications.commands&permissions=8
```

### Development

If you're looking at the source code, you should probably run

```sh
npx prisma generate
```

first so you can have typings.
Loading

0 comments on commit c7b9ab6

Please sign in to comment.