Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
chore(docker): improved docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh committed Apr 9, 2023
1 parent 44bc8d3 commit 3c56858
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 43 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/docker-nightly-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Docker nightly release

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
check_date:
runs-on: ubuntu-latest
name: Check latest commit
outputs:
should_run: ${{ steps.should_run.outputs.should_run }}
steps:
- uses: actions/checkout@v2
- name: print latest_commit
run: echo ${{ github.sha }}

- id: should_run
continue-on-error: true
name: check latest commit is less than a day
if: ${{ github.event_name == 'schedule' }}
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false"

ci:
runs-on: ubuntu-latest
needs: check_date
if: ${{ needs.check_date.outputs.should_run != 'false' }}

steps:
- uses: actions/checkout@v3
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'pnpm'

- name: Install dependencies
run: pnpm i

- name: Run linters
run: pnpm lint

- name: Run unit test
run: pnpm test

- name: Build the app
run: pnpm build

build:
runs-on: ubuntu-latest
needs:
- ci

steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

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

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

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
corentinth/snut:nightly
ghcr.io/corentinth/snut:nightly
43 changes: 16 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
FROM node:16-alpine as development

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install
RUN apk add --update sqlite

FROM node:16.20-alpine AS build
WORKDIR /app
RUN npm install -g pnpm
RUN apk add --update python3 make g++ sqlite && rm -rf /var/cache/apk/*
COPY . .
RUN pnpm i --frozen-lockfile
RUN pnpm build

RUN npm run build

FROM node:16-alpine as production

FROM node:16.20-alpine as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

RUN apk add --update sqlite

COPY package*.json ./

RUN npm install --only=production

COPY . .

COPY --from=development /usr/src/app/dist ./dist

CMD ["node", "dist/main"]
WORKDIR /app
RUN apk add --update sqlite && rm -rf /var/cache/apk/*
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/package*.json ./
COPY --from=build /app/views ./views
COPY --from=build /app/public ./public
EXPOSE 3000
CMD ["npm", "start"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

Another pastebin with a clean and minimalist ui. Made for selfhosting.

Use it online : [snut.thomasset.co](https://snut.thomasset.co/)

![screenshot](./.github/screenshot.png)

## Host your instance

### Installation

Install using docker
```shell
docker run -d --restart unless-stopped -v $(pwd)/db:/app/db -e DATABASE_PATH=/app/db/db.sqlite -p 3000:3000 --name snut corentinth/snut:latest
```

### Configuration

Expand Down
23 changes: 8 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
version: '3'

version: '3.9'
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
- NODE_ENV=production
environment:
- PORT=3000
- DATABASE_PATH=/usr/src/app/db/db.sqlite
snut:
image: 'corentinth/snut:latest'
container_name: snut
ports:
- 3000:3000
- '3000:3000'
environment:
- DATABASE_PATH=/app/db/db.sqlite
volumes:
- ./test-db:/usr/src/app/db
- '.db:/app/db'
restart: unless-stopped
volumes:
test-db:

0 comments on commit 3c56858

Please sign in to comment.