diff --git a/.dockerignore b/.dockerignore index 43c4efd..31217f1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,4 @@ -.env -.env.dev .env.prod +.env.dev /node_modules npm-debug-log \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..563de67 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,20 @@ +name: Deploy Discord-Study + +on: + push: + branches: + - "main" + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: code checkout + uses: actions/checkout@v2 + + - name: install gcloud CLI + uses: google-github-actions/setup-gcloud@v0 + with: + project_id: ${{secrets.GOOGLE_PROJECT}} + service_account_key: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} + export_default_credentials: true diff --git a/.gitignore b/.gitignore index 59100f3..ac6c5dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .env .env.dev .env.prod -/node_modules -Dockerfile \ No newline at end of file +/node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3de9a55 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +## set base image +FROM node:20-alpine + + +## set working directory +WORKDIR /usr/src/app + +## COPY necessory files +COPY package*.json ./ + +## Install necessory packages +RUN npm ci + +COPY . . + + +CMD ["npm", "run","start"] \ No newline at end of file diff --git a/client.js b/client.js index 1884458..64ecbea 100644 --- a/client.js +++ b/client.js @@ -142,7 +142,7 @@ client.on("voiceStateUpdate", (oldState, newState) => { }); client.login(process.env.DISCORD_TOKEN).catch((error) => { - console.log(err); + console.log(error); process.exit(1); }); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d9246b0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: "3" +services: + discord-study-v2: + image: discord-study-v2 + container_name: discord-study-v2 + build: + context: . + dockerfile: Dockerfile + env_file: + - .env diff --git a/duration.js b/duration.js index cb8da2e..4781dea 100644 --- a/duration.js +++ b/duration.js @@ -10,7 +10,7 @@ function initUserState(userInfo, state) { enter: new Date(), ...state }); - // console.log(`${id}:${name} joined`); + console.log(`${id}:${name} joined`); // console.log(userState.get(id)) diff --git a/index.js b/index.js index d15a298..f31aaf5 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,20 @@ const dotenv = require("dotenv"); let path; + switch (process.env.NODE_ENV) { case "dev": path = `${__dirname}/.env.dev`; break; case "prod": path = `${__dirname}/.env.prod`; + break; default: path = `${__dirname}/.env`; } -console.log(path, `${process.env.NODE_ENV}`); +console.log(path, `${process.env.NODE_ENV} ${process.env.DISCORD_TOKEN}`); dotenv.config({ path: path }); // path 설정 const client = require("./client");