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

Add docker support #31

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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
**/.github
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
64 changes: 64 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Publish Docker image
on:
push:
branches:
- "master"
- "main"
workflow_dispatch: # allows manual triggering
release:
types: [published]

jobs:
push_to_registry:
runs-on: ubuntu-latest
steps:
- name: Get current date
run: echo "curr_date=$(date --utc +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push ${{github.event.release.tag_name }}
id: docker_build_release
uses: docker/build-push-action@v5
if: ${{ github.event.release.tag_name != '' }}
with:
pull: true
push: true
tags: ghcr.io/mangosango/clive:latest,ghcr.io/mangosango/clive:${{ github.event.release.tag_name }}
platforms: linux/amd64,linux/arm64
provenance: false
build-args: |
VERSION=${{ github.event.release.tag_name }}
BUILD=${{ env.curr_date }}

- name: Check for commits in the last 24 hours
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV
if: ${{ github.event.release.tag_name == '' }}

- name: Build and push main
id: docker_build_main
uses: docker/build-push-action@v5
if: ${{ github.event.release.tag_name == '' && env.NEW_COMMIT_COUNT > 0 }}
with:
pull: true
push: true
tags: ghcr.io/mangosango/clive:main
platforms: linux/amd64,linux/arm64
provenance: false
build-args: |
VERSION=main
BUILD=${{ env.curr_date }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1
ARG NODE_VERSION=20

FROM node:${NODE_VERSION}-alpine

# Use production node environment by default.
ENV NODE_ENV production
ENV LOG_FILE /config/logs/clive.log
ENV DB_FILE /config/db.json

WORKDIR /app

# 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 a bind mounts to package.json and package-lock.json to avoid having to copy them into
# into this layer.
RUN mkdir /config
RUN chown -R node:node /app /config
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

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

# Copy the rest of the source files into the image.
COPY --chown=node:node . .

# Run the application.
CMD npm start
20 changes: 20 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
clive:
image: ghcr.io/mangosango/clive:latest
volumes:
- /path/to/db_and_logs_folder:/config
# environment:
# NODE_ENV: production
# LOG_LEVEL: error
# DISCORD_WEBHOOK_URL: https://discordapp.com/api/webhooks/YOUR_DISCORD/WEBHOOK_URL_HERE
# TWITCH_CHANNELS: "a_twitch_channel another_twitch_channel"
# TWITCH_CLIENT_ID: <twitch_client_id>
# TWITCH_CLIENT_SECRET: <twitch_client_secret>
# RESTRICT_CHANNELS: true
# MODS_ONLY: false
# SUBS_ONLY: false
# BROADCASTER_ONLY: false
# RICH_EMBED: true
# URL_AVATAR: http://i.imgur.com/9s3TBNv.png
# BOT_USERNAME: "Clive"
# env_file: .env # Alternatly use a .env file
Loading