From 0ae0a2e08ecc35484b96d18eb6c1eb6d749c1eff Mon Sep 17 00:00:00 2001 From: AlphaNecron Date: Mon, 4 Oct 2021 10:56:00 +0700 Subject: [PATCH] feat(docker): docker support --- .dockerignore | 4 +++ .github/workflows/docker.yml | 41 +++++++++++++++++++++++++++++++ Dockerfile | 33 +++++++++++++++++++++++++ docker-compose.yml | 47 ++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c3b4887 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules/ +.next/ +uploads/ +.git/ \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d91f713 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,41 @@ +name: 'docker push' + +on: + push: + branches: [ v0 ] + paths: + - 'src/**' + - 'server/**' + - 'prisma/**' + - '.github/**' + workflow_dispatch: +jobs: + push_to_ghcr: + name: push to github packages + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - name: push + uses: docker/build-push-action@v1 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: docker.pkg.github.com + repository: AlphaNecron/Void/Void + dockerfile: Dockerfile + tag_with_ref: true + push_to_dockerhub: + name: push to dockerhub + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - name: push + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: alphaNecron/void + dockerfile: Dockerfile + tag_with_ref: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4fd740a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:fermium-alpine3.14 AS builder +WORKDIR /build + +ENV NEXT_TELEMETRY_DISABLED=1 + +COPY src ./src +COPY server ./server +COPY scripts ./scripts +COPY prisma ./prisma + +COPY package.json yarn.lock next.config.js next-env.d.ts zip-env.d.ts tsconfig.json ./ + +RUN yarn install + +# create a mock config.toml to spoof next build! +RUN echo -e "[core]\nsecret = 'dockersecret'\ndatabase_url = 'postgres://postgres:postgres@postgres/postgres'\n[uploader]\nraw_route = '/r'\ndirectory = './uploads'\n[shortener]\nroute = '/go'" > config.toml + +RUN yarn build + +FROM node:fermium-alpine3.14 AS runner +WORKDIR /Void + +COPY --from=builder /build/node_modules ./node_modules + +COPY --from=builder /build/src ./src +COPY --from=builder /build/server ./server +COPY --from=builder /build/scripts ./scripts +COPY --from=builder /build/prisma ./prisma +COPY --from=builder /build/.next ./.next +COPY --from=builder /build/tsconfig.json ./tsconfig.json +COPY --from=builder /build/package.json ./package.json + +CMD ["node", "server"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5d770c9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +version: '3' +services: + postgres: + image: postgres + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DATABASE=postgres + volumes: + - pg_data:/var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U postgres'] + interval: 10s + timeout: 5s + retries: 5 + + zipline: + image: ghcr.io/AlphaNecron/Void/Void:v0 + ports: + - '3000:3000' + restart: unless-stopped + environment: + - SECURE=false + - SECRET=changethisplease + - HOST=0.0.0.0 + - PORT=3000 + - DATABASE_URL=postgresql://postgres:postgres@postgres/postgres/ + - UPLOADER_RAW_ROUTE=/u + - UPLOADER_LENGTH=6 + - UPLOADER_DIRECTORY=./uploads + - UPLOADER_BLACKED= + - SHORTENER_ROUTE=/go + - SHORTENER_LENGTH=6 + - BOT_ENABLED=false + - BOT_TOKEN= + - BOT_PREFIX=& + - BOT_ADMINS= + - BOT_LOG_CHANNEL= + - BOT_HOSTNAME=localhost + volumes: + - '$PWD/uploads:/Void/uploads' + - '$PWD/public:/Void/public' + depends_on: + - 'postgres' + +volumes: + pg_data: \ No newline at end of file diff --git a/package.json b/package.json index dbbad98..2a4ffc5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "void", - "version": "0.2.3", + "version": "0.3.0", "private": true, "engines": { "node": ">=14" @@ -136,6 +136,7 @@ "prisma", "scripts", "server", + "docker", "pages", "config", "api",