Skip to content

Commit

Permalink
Dockerize slackbot and setup prod server
Browse files Browse the repository at this point in the history
  • Loading branch information
Archit404Error committed Aug 16, 2023
1 parent 84ebeff commit bca026b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Deploy to Cloud VM

on:
push:
branches:
- "main"

jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Auth Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Get SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

# Build the Docker image
- name: Build
run: |-
docker build --tag "cuappdev/big-red-bot:${{ steps.vars.outputs.sha_short }}" .
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "cuappdev/big-red-bot:${{ steps.vars.outputs.sha_short }}"
- name: SSH & Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
export SLACK_BOT_IMG_TAG="${{ steps.vars.outputs.sha_short }}"
docker stop big-red-bot-backend-web-1
docker rm big-red-bot-backend-web-1
yes | sudo docker container prune
yes | sudo docker system prune
docker compose -p big-red-bot-backend up -d
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:16

RUN mkdir /usr/app
WORKDIR /usr/app

# Copy these files first to optimize cache
COPY package.json .
COPY yarn.lock .

RUN yarn install
COPY . .
EXPOSE 3000 8000
CMD ["yarn", "start"]
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
web:
image: cuappdev/big-red-bot:${SLACK_BOT_IMG_TAG}
env_file: .env
ports:
- "3000:3000"
- "8000:8000"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"typescript": "^5.1.6"
},
"scripts": {
"start": "ts-node -r dotenv/config src/index.ts",
"start": "ts-node --transpile-only -r dotenv/config src/index.ts",
"dev": "nodemon -r dotenv/config src/index.ts"
}
}

0 comments on commit bca026b

Please sign in to comment.