From b17b653225e0949dd0fdbc324d0fbc6491984415 Mon Sep 17 00:00:00 2001 From: Patrick Gallagher Date: Sat, 25 Sep 2021 01:25:54 -0500 Subject: [PATCH 1/3] Add Dockerfile and config builds --- .dockerignore | 1 + Dockerfile | 16 ++++++++++++++++ package.json | 3 ++- tsconfig.json | 6 ++++-- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ee83a25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1 + +FROM node:16-alpine + +WORKDIR /app + +COPY ["package.json", "yarn.lock", "./"] + +RUN yarn install --production +RUN yarn global add typescript + +COPY . . + +RUN yarn build + +CMD [ "node", "built/index.js" ] diff --git a/package.json b/package.json index c6fb135..0b40eee 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "mongodb": "^4.1.1" }, "scripts": { - "start": "ts-node src/index.ts" + "start": "ts-node src/index.ts", + "build": "tsc -p ." }, "devDependencies": { "ts-node": "^10.2.1", diff --git a/tsconfig.json b/tsconfig.json index d4364cd..a49b839 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,9 @@ "outDir": "./built", "allowJs": true, "target": "es2017", - "moduleResolution": "node" + "moduleResolution": "node", + "module": "commonjs", + "esModuleInterop": true }, "include": ["./src/**/*"] -} \ No newline at end of file +} From 0ed7b689c051201c3e4a231d509fae00141683e9 Mon Sep 17 00:00:00 2001 From: Patrick Gallagher Date: Sat, 25 Sep 2021 01:26:09 -0500 Subject: [PATCH 2/3] Add docker to GH action pipeline --- .github/workflows/main.yml | 55 +++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fcb99e1..b0db330 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,27 +1,58 @@ -# This is a basic workflow to help you get started with Actions +name: CI Docker Release -name: CI - -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the master branch release: branches: [ master ] - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on + publish: runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job steps: - name: Checkout uses: actions/checkout@v2 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/cypherbot:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + + deploy: + needs: publish + runs-on: ubuntu-latest + + steps: - name: Install SSH Key uses: shimataro/ssh-key-action@v2 with: @@ -30,4 +61,4 @@ jobs: - name: Adding Known Hosts run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts - name: Deploy with rsync - run: rsync -avz . ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/cypher-bot/server \ No newline at end of file + run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker pull cypher-bot:latest" \ No newline at end of file From 0c602fffda0d9b9d5ed18fc76b29eb671658c118 Mon Sep 17 00:00:00 2001 From: Patrick Gallagher Date: Sat, 25 Sep 2021 01:44:52 -0500 Subject: [PATCH 3/3] Fix bugs preventing service from starting --- src/client.ts | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index a5e90cd..3194cda 100644 --- a/src/client.ts +++ b/src/client.ts @@ -38,7 +38,7 @@ export default (db: Db) => { console.log(`Logged in as ${client.user.tag}!`); console.log(`Loading configuration data from db...`); - await initBotConfig(this, db); + await initBotConfig(client, db); console.log(`Config successfully initialized.`); }); diff --git a/src/index.ts b/src/index.ts index 5821dce..c803c1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -94,7 +94,7 @@ const commands = [ description: "Configure Cypher Bot settings via subcommands", options: [ { - name: "defaultChannel", + name: "default_channel", description: "The channel to place queue embed messages", type: ApplicationCommandOptionType.Subcommand, options: [