Skip to content

Commit 5e1f5fc

Browse files
committed
chore(*): prod and env handling
* composed .env files * split Dockerfile and compose files * start script based on env
1 parent ab69802 commit 5e1f5fc

File tree

9 files changed

+47
-19
lines changed

9 files changed

+47
-19
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# secrets
2-
.env
2+
*.env
33

44
# build flow
55
dist/
@@ -9,4 +9,4 @@ node_modules/
99
.DS_Store
1010
.yarn/*
1111
!.yarn/releases
12-
!.yarn/patches
12+
!.yarn/patches

DevDockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:20-alpine
2+
LABEL name "slash-utils"
3+
LABEL version "0.0.0"
4+
LABEL maintainer "almostSouji <https://github.com/almostSouji>"
5+
ENV FORCE_COLOR=1
6+
WORKDIR /usr/slash-utils
7+
COPY package.json ./
8+
COPY . .
9+
RUN yarn build
10+
CMD ["yarn", "start"]

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ WORKDIR /usr/slash-utils
77
COPY package.json ./
88
COPY . .
99
RUN yarn build
10-
CMD ["yarn", "start"]
10+
CMD ["yarn", "start"]

compose.dev.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1+
version: '3'
2+
13
services:
24
application:
5+
build:
6+
context: ./
7+
dockerfile: dev.Dockerfile
8+
restart: always
9+
env_file:
10+
- ./.env
11+
- ./.dev.env
312
ports:
413
- '49202:49666'
14+
volumes:
15+
- type: bind
16+
source: ./tags
17+
target: /usr/slash-utils/tags

dev.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:20-alpine
2+
LABEL name "slash-utils-dev"
3+
LABEL version "0.0.0"
4+
LABEL maintainer "almostSouji <https://github.com/almostSouji>"
5+
ENV FORCE_COLOR=1
6+
WORKDIR /usr/slash-utils
7+
COPY package.json ./
8+
COPY . .
9+
RUN yarn build
10+
CMD ["yarn", "start"]

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
"lint": "eslint src --ext .ts",
99
"lint:fix": "eslint src --ext .ts --fix",
1010
"prettier": "prettier --write **/*.{ts,js,toml}",
11-
"cmd:glob": "env-cmd node dist/deployFunctions/deployGlobal.js",
12-
"cmd:dev": "env-cmd node dist/deployFunctions/deployDev.js",
11+
"deploy:glob": "env-cmd node dist/deployFunctions/deployGlobal.js --env-file=.env",
12+
"deploy:dev": "env-cmd node dist/deployFunctions/deployDev.js --env-file=.env",
13+
"deploy-dev:glob": "env-cmd node dist/deployFunctions/deployGlobal.js --env-file=.env --env-file=.dev.env",
14+
"deploy-dev:dev": "env-cmd node dist/deployFunctions/deployDev.js --env-file=.env --env-file=.dev.env",
1315
"validate-tags": "node dist/workflowFunctions/validateTagsWithoutLinks.js",
1416
"validate-tags:withlinks": "node dist/workflowFunctions/validateTagsWithLinks.js",
1517
"prepare": "is-ci || husky install"
@@ -37,7 +39,6 @@
3739
"cheerio": "^1.0.0-rc.12",
3840
"cloudflare": "^4.2.0",
3941
"discord-api-types": "^0.37.83",
40-
"dotenv": "^16.3.1",
4142
"he": "^1.2.0",
4243
"html-entities": "^2.4.0",
4344
"kleur": "^4.1.5",

src/deployFunctions/deploy.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import { resolve, dirname } from 'node:path';
21
import process from 'node:process';
3-
import { fileURLToPath } from 'node:url';
4-
import { config } from 'dotenv';
52
import { fetch } from 'undici';
63
import { API_BASE_DISCORD } from '../util/constants.js';
74
import { logger } from '../util/logger.js';
85
import { PreReleaseApplicationCommandContextType, PreReleaseApplicationIntegrationType } from './auxtypes.js';
96

10-
config({ path: resolve(dirname(fileURLToPath(import.meta.url)), '../../.env') });
11-
127
export async function deploy(data: any, dev = false) {
138
const midRoute = dev ? `/guilds/${process.env.DISCORD_DEVGUILD_ID!}` : '';
149
const route = `${API_BASE_DISCORD}/applications/${process.env.DISCORD_CLIENT_ID!}${midRoute}/commands`;

start.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /bin/bash
2+
3+
if [ "$ENV" = "dev" ]; then
4+
podman-compose -p discord-utils-bot-dev down && podman-compose -f ./compose.dev.yml -p discord-utils-bot-dev up --build
5+
else
6+
podman-compose -p discord-utils-bot down && podman-compose -f ./compose.yml -p discord-utils-bot up --build
7+
fi

yarn.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,13 +2717,6 @@ __metadata:
27172717
languageName: node
27182718
linkType: hard
27192719

2720-
"dotenv@npm:^16.3.1":
2721-
version: 16.4.5
2722-
resolution: "dotenv@npm:16.4.5"
2723-
checksum: 301a12c3d44fd49888b74eb9ccf9f07a1f5df43f489e7fcb89647a2edcd84c42d6bc349dc8df099cd18f07c35c7b04685c1a4f3e6a6a9e6b30f8d48c15b7f49c
2724-
languageName: node
2725-
linkType: hard
2726-
27272720
"dunder-proto@npm:^1.0.1":
27282721
version: 1.0.1
27292722
resolution: "dunder-proto@npm:1.0.1"
@@ -7142,7 +7135,6 @@ __metadata:
71427135
cheerio: ^1.0.0-rc.12
71437136
cloudflare: ^4.2.0
71447137
discord-api-types: ^0.37.83
7145-
dotenv: ^16.3.1
71467138
env-cmd: ^10.1.0
71477139
eslint: ^8.48.0
71487140
eslint-config-neon: 0.1.54

0 commit comments

Comments
 (0)