diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9caaf11b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.github +.next +.yarn/cache +.yarn/install-state.gz +build +node_modules +public +uploads +.env +.eslintcache \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e08d2f3d..79b00b14 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} - + - name: 'Restore dependency cache' id: cache-restore uses: actions/cache@v3 @@ -31,17 +31,13 @@ jobs: key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} restore-keys: | ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}- - - + - name: Install dependencies if: steps.cache-restore.outputs.cache-hit != 'true' run: yarn install - - - name: Build - env: - ZIPLINE_BUILD: 'true' - run: yarn build - - - + - name: Build + env: + ZIPLINE_BUILD: 'true' + NEXT_TELEMETRY_DISABLED: '1' + run: yarn build diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..c507f082 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,35 @@ +name: 'Push Docker Images' + +on: + push: + branches: [v4] + workflow_dispatch: + +jobs: + push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Get commit sha + id: sha + run: | + echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/build-push-action@v4 + with: + push: true + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + tags: | + ghcr.io/diced/zipline:v4 + ghcr.io/diced/zipline:v4-${{ steps.sha.outputs.short_sha }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8389848d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,61 @@ +# FROM ghcr.io/diced/prisma-binaries:4.10.x as prisma-binaries + +FROM node:18-alpine3.16 as base + +WORKDIR /zipline + +# Prisma binaries +# COPY --from=prisma /prisma-engines /prisma-engines +# ENV PRISMA_QUERY_ENGINE_BINARY=/prisma-engines/query-engine \ +# PRISMA_MIGRATION_ENGINE_BINARY=/prisma-engines/migration-engine \ +# PRISMA_INTROSPECTION_ENGINE_BINARY=/prisma-engines/introspection-engine \ +# PRISMA_FMT_BINARY=/prisma-engines/prisma-fmt \ +# PRISMA_CLI_QUERY_ENGINE_TYPE=binary \ +# PRISMA_CLIENT_ENGINE_TYPE=binary \ +# ZIPLINE_BUILD=true \ +# NEXT_TELEMETRY_DISABLED=1 \ +# NODE_ENV=production + +ENV NEXT_TELEMETRY_DISABLED=1 \ + NODE_ENV=production + +# Copy the necessary files from the project +COPY prisma ./prisma +COPY .yarn ./.yarn +COPY package.json ./ +COPY yarn.lock ./ +COPY .yarnrc.yml ./ + +# Install the dependencies +RUN yarn install --immutable + +FROM base as builder + +COPY src ./src +COPY next.config.js ./next.config.js +COPY tsup.config.ts ./tsup.config.ts +COPY tsconfig.json ./tsconfig.json +COPY mimes.json ./mimes.json +COPY code.json ./code.json +COPY themes ./themes + +# Run the build +RUN ZIPLINE_BUILD=true yarn build + +# Use Alpine Linux as the final image +FROM base + +COPY --from=builder /zipline/build ./build +COPY --from=builder /zipline/.next ./.next + +COPY --from=builder /zipline/mimes.json ./mimes.json +COPY --from=builder /zipline/code.json ./code.json + +# remove the ZIPLINE_BUILD env var +RUN unset ZIPLINE_BUILD + +# clean +RUN yarn cache clean --all +RUN rm -rf /tmp/* /root/* + +CMD ["node", "--enable-source-maps", "build/server.js"] \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..cc2075f3 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,36 @@ +version: '3' +services: + postgres: + image: postgres:15 + restart: unless-stopped + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DATABASE=postgres + volumes: + - pgdata:/var/lib/postgresql/data + healthcheck: + test: ['CMD', 'pg_isready', '-U', 'postgres'] + interval: 10s + timeout: 5s + retries: 5 + + zipline: + build: + context: . + dockerfile: Dockerfile + ports: + - '3000:3000' + env_file: + - .env + environment: + - DATABASE_URL=postgres://postgres:postgres@postgres/postgres + depends_on: + - postgres + volumes: + - './uploads:/zipline/uploads' + - './public:/zipline/public' + - './themes:/zipline/themes' + +volumes: + pgdata: