Skip to content

Commit

Permalink
Merge pull request #23 from pattyjogal/containerization
Browse files Browse the repository at this point in the history
Containerization
  • Loading branch information
pattyjogal authored Sep 25, 2021
2 parents 1904afe + 0c602ff commit 1b8597a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 17 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
55 changes: 43 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker pull cypher-bot:latest"
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
});

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"outDir": "./built",
"allowJs": true,
"target": "es2017",
"moduleResolution": "node"
"moduleResolution": "node",
"module": "commonjs",
"esModuleInterop": true
},
"include": ["./src/**/*"]
}
}

0 comments on commit 1b8597a

Please sign in to comment.