Skip to content

Commit

Permalink
Adding docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
JH220 committed Jul 20, 2024
1 parent 2120c58 commit b68289d
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 67 deletions.
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
*.md
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules/
dist/
config.json
ccbot.log
config.docker.json
ccbot.log
db-data/
docker-compose.y*ml
69 changes: 69 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# syntax=docker/dockerfile:1
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG NODE_VERSION=20.9.0

################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base

# Set working directory for all build stages.
WORKDIR /usr/src/app


################################################################################
# Create a stage for installing production dependecies.
FROM base as deps

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
# Leverage bind mounts to package.json and package-lock.json to avoid having to copy them
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --omit=dev

################################################################################
# Create a stage for building the application.
FROM deps as build

# Download additional development dependencies before building, as some projects require
# "devDependencies" to be installed to build. If you don't need this, remove this step.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci

# Copy the rest of the source files into the image.
COPY . .
# Run the build script.
RUN npm run build

################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM base as final

# Use production node environment by default.
ENV NODE_ENV production

# Run the application as a non-root user.
USER node

# Copy package.json so that package manager commands can be used.
COPY package.json .

# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist


# Expose top.gg webhook port.
EXPOSE 1337

# Run the application.
CMD node ./dist/index.js
22 changes: 22 additions & 0 deletions README.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Building and running your application

When you're ready, start your application by running:
`docker compose up --build`.

Your application will be available at http://localhost:1337.

### Deploying your application to the cloud

First, build your image, e.g.: `docker build -t myapp .`.
If your cloud uses a different CPU architecture than your development
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
you'll want to build the image for that platform, e.g.:
`docker build --platform=linux/amd64 -t myapp .`.

Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.

Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
docs for more detail on building and pushing.

### References
* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/)
2 changes: 1 addition & 1 deletion config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Important: This file/data is only for illustration purposes to show how the actu
{
"token": "INSERT_YOUR_BOT_TOKEN_HERE",
"clientId": "INSERT_YOUR_CLIENT_ID_HERE",
"database": "mysql://user:pass@host:3306/dbname", // Unterstützt auch SQLite, PostgreSQL
"database": "postgres://postgres:password@db:5432/clearchat", // "mysql://root:password@localhost:3306/clearchat"
"adminServerId": "789235487676170261",
"supportServerURL": "https://github.com/jh220de/ccbot", // Normalerweise discord.gg Link zum Support Discord Server
"log": {
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
server:
build:
context: .
environment:
NODE_ENV: production
ports:
- 1337:1337
volumes:
- ./config.json:/usr/src/app/config.json:ro
- ./ccbot.log:/usr/src/app/ccbot.log:rw
depends_on:
- db
db:
image: postgres
restart: always
user: postgres
environment:
- POSTGRES_DB=clearchat
- POSTGRES_PASSWORD=password
volumes:
- ./db-data:/var/lib/postgresql/data
expose:
- 5432
Loading

0 comments on commit b68289d

Please sign in to comment.