Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize #5

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4ee358f
Dockerized application
moulikbhardwaj Aug 25, 2021
95bf0b3
removed secrets from repo, moved to environment secrets
moulikbhardwaj Aug 25, 2021
d280c5f
Added workflow for GCP-Deploy
moulikbhardwaj Aug 25, 2021
6df73d2
Merge pull request #1 from moulikbhardwaj/dockerize
moulikbhardwaj Aug 25, 2021
52b41ba
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
e0a8d83
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
21a33ac
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
d4fd089
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
8a2c3c8
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
53ba7f3
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
47f8487
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
597ee9a
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
83d5122
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
b6493df
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
ad61ed7
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
a7a5624
Create GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
2be6b3b
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
4b99f77
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
c7395ca
added server for health probe
moulikbhardwaj Aug 25, 2021
c080959
added server for health probe
moulikbhardwaj Aug 25, 2021
8c99817
Merge pull request #2 from moulikbhardwaj/dockerize
moulikbhardwaj Aug 25, 2021
4644851
Update Dockerfile
moulikbhardwaj Aug 25, 2021
1e62a82
Update app.js
moulikbhardwaj Aug 25, 2021
c8c9960
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
f4c5b2a
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
7d184d2
Update app.js
moulikbhardwaj Aug 25, 2021
cd5e35d
Update app.js
moulikbhardwaj Aug 25, 2021
5f3fb73
Update app.js
moulikbhardwaj Aug 25, 2021
d1bd52f
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
f04123b
Update GCP-Deploy.yml
moulikbhardwaj Aug 25, 2021
316227f
Update GCP-Deploy.yml
moulikbhardwaj Aug 26, 2021
e86b0cd
seperated deploy and build
moulikbhardwaj Aug 26, 2021
e6ac3dd
fix
moulikbhardwaj Aug 26, 2021
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
66 changes: 66 additions & 0 deletions .github/workflows/GCP-Deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: GCP-deploy

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
environment: spartaBot
name: Setup Gcloud Account
runs-on: ubuntu-latest
env:
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }}

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

- name: Login
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_EMAIL }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}

- name: Configure Docker
run: gcloud auth configure-docker --quiet

- name: Build Docker Image
run: docker build . -t $IMAGE_NAME

- name: Push Docker Image
run: docker push $IMAGE_NAME

deploy:
needs: build
environment: spartaBot
name: Setup Gcloud Account
runs-on: ubuntu-latest
env:
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }}
MONGODB_URL: '${{ secrets.MONGODB_URL }}'
BOT_COMMAND: '${{ secrets.BOT_COMMAND }}'
TAG_COMMAND: '${{ secrets.TAG_COMMAND }}'
WW_SESSION: '${{ secrets.WW_SESSION }}'
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Login
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_EMAIL }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}

- name: Deploy Docker Image
run: gcloud run deploy $GCP_PROJECT_ID\
--set-env-vars ^]^WW_SESSION=$WW_SESSION\
--set-env-vars MONGODB_URL=$MONGODB_URL\
--set-env-vars BOT_COMMAND=$BOT_COMMAND\
--set-env-vars TAG_COMMAND=$TAG_COMMAND\
--image $IMAGE_NAME --region asia-south1\
--platform managed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ deletedMessages.json
yarn-error.log
.env
package-lock.json
key.json
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:16.4.2

WORKDIR /home/node/mikuBot
COPY package*.json ./
COPY yarn.lock ./
RUN npm install

RUN apt update && \
apt install -y \
chromium\
ffmpeg


RUN wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
RUN chmod a+rx /usr/local/bin/youtube-dl

RUN npm install whatsapp-web.js
RUN ln -s /bin/bash /usr/bin/bash

# ENV MONGODB_URL= Mongo DB url
# ENV BOT_COMMAND= Bot command
# ENV TAG_COMMAND= command for mentioning all people in group
ENV CHROME_PATH="/usr/bin/chromium"
ENV HEADLESS=true
ENV TZ="Asia/Kolkata"
ENV DOCKER=true
# ENV WW_SESSION= whatsapp session details

COPY . .


EXPOSE 3000
CMD ["node", "app.js" ]
7 changes: 6 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const _ = require('./src/globals');
const miku = require('./src/miku');
const db = require('./src/database/dbfunctions');
const emojiStrip = require('emoji-strip');

const deleted = require('./src/database/models/deleted');

// LOAD THE SESSION DATA IF IT HAS BEEN SAVED PREVIOUSLY
Expand Down Expand Up @@ -86,6 +85,12 @@ client.on('message_revoke_everyone', async (after, before) => {
})
}
})
const express = require('express')
const app = express();
const port = process.env.PORT || 8080;
const server = app.listen(port, () =>{
console.log("listening on port", port);
});

client.initialize();

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"author": "Coder_H",
"license": "MIT",
"private": true,
"workspaces": [ "whatsapp-web.js" ],
"workspaces": [
"whatsapp-web.js"
],
"scripts": {
"miku": "node app.js"
},
Expand All @@ -20,6 +22,7 @@
"cheerio": "^1.0.0-rc.10",
"dotenv": "^10.0.0",
"emoji-strip": "^1.0.1",
"express": "^4.17.1",
"mongoose": "^5.13.2",
"puppeteer": "^10.1.0",
"qrcode-terminal": "^0.12.0"
Expand Down