Skip to content

Commit 9fb7032

Browse files
authored
Add better docker support (#76)
* Add better docker support * Update readme
1 parent 4af4b8d commit 9fb7032

File tree

19 files changed

+651
-336
lines changed

19 files changed

+651
-336
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ yarn-error.log*
3434
# local env files
3535
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
3636
# .env
37+
.env
3738
.env.example
3839
.env*.local
3940

@@ -50,5 +51,7 @@ yarn-error.log*
5051
**/public/worker-*.js
5152
src/server/random.code-workspace
5253

54+
prisma/seed.ts
55+
5356
creds
5457
package-lock.json

.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ DATABASE_URL="postgresql://postgres@localhost:5435/"
99

1010
# These variables are also used by docker compose in compose.yml to name the container
1111
# and initialise postgres with default username, password
12-
# POSTGRES_HOST="split-pro-pg"
13-
# POSTGRES_PORT="5432"
1412
# POSTGRES_USER="postgres"
1513
# POSTGRES_PASSWORD="strong-password"
14+
# POSTGRES_DB="splitpro"
15+
# DATABASE_URL="postgresql://postgres:strong-password@splitpro-db-prod:5432/splitpro"
1616

1717
# Required
1818
# Next Auth
@@ -21,7 +21,6 @@ DATABASE_URL="postgresql://postgres@localhost:5435/"
2121
# https://next-auth.js.org/configuration/options#secret
2222
NEXTAUTH_SECRET="secret"
2323
NEXTAUTH_URL="http://localhost:3000"
24-
NEXT_PUBLIC_URL="http://localhost:3000"
2524

2625

2726
GOOGLE_CLIENT_ID=

.github/workflows/publish.yaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Publish Docker
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: 'Branch to run the action on'
11+
default: 'main'
12+
required: true
13+
14+
jobs:
15+
build_and_publish_platform_containers:
16+
name: Build and publish platform containers
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
platform:
24+
- linux/amd64
25+
- linux/arm64
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v3
34+
35+
- name: Login to DockerHub
36+
uses: docker/login-action@v3
37+
with:
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
41+
- name: Login to GitHub Container Registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.repository_owner }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Build the docker image
49+
env:
50+
BUILD_PLATFORM: ${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }}
51+
run: |
52+
APP_VERSION="$(git name-rev --tags --name-only $(git rev-parse HEAD) | head -n 1 | sed 's/\^0//')"
53+
GIT_SHA="$(git rev-parse HEAD)"
54+
55+
docker build \
56+
-f ./docker/Dockerfile \
57+
--progress=plain \
58+
-t "ossapps/splitpro-$BUILD_PLATFORM:latest" \
59+
-t "ossapps/splitpro-$BUILD_PLATFORM:$GIT_SHA" \
60+
-t "ossapps/splitpro-$BUILD_PLATFORM:$APP_VERSION" \
61+
-t "ghcr.io/oss-apps/splitpro-$BUILD_PLATFORM:latest" \
62+
-t "ghcr.io/oss-apps/splitpro-$BUILD_PLATFORM:$GIT_SHA" \
63+
-t "ghcr.io/oss-apps/splitpro-$BUILD_PLATFORM:$APP_VERSION" \
64+
.
65+
66+
- name: Push the docker image to DockerHub
67+
run: docker push --all-tags "ossapps/splitpro-$BUILD_PLATFORM"
68+
env:
69+
BUILD_PLATFORM: ${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }}
70+
71+
- name: Push the docker image to GitHub Container Registry
72+
run: docker push --all-tags "ghcr.io/oss-apps/splitpro-$BUILD_PLATFORM"
73+
env:
74+
BUILD_PLATFORM: ${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }}
75+
76+
create_and_publish_manifest:
77+
name: Create and publish manifest
78+
runs-on: ubuntu-latest
79+
permissions:
80+
packages: write
81+
needs: build_and_publish_platform_containers
82+
steps:
83+
- name: Checkout
84+
uses: actions/checkout@v4
85+
with:
86+
fetch-depth: 0
87+
88+
- name: Login to DockerHub
89+
uses: docker/login-action@v3
90+
with:
91+
username: ${{ secrets.DOCKERHUB_USERNAME }}
92+
password: ${{ secrets.DOCKERHUB_TOKEN }}
93+
94+
- name: Login to GitHub Container Registry
95+
uses: docker/login-action@v3
96+
with:
97+
registry: ghcr.io
98+
username: ${{ github.repository_owner }}
99+
password: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Create and push DockerHub manifest
102+
run: |
103+
APP_VERSION="$(git name-rev --tags --name-only $(git rev-parse HEAD) | head -n 1 | sed 's/\^0//')"
104+
GIT_SHA="$(git rev-parse HEAD)"
105+
106+
docker manifest create \
107+
ossapps/splitpro:latest \
108+
--amend ossapps/splitpro-amd64:latest \
109+
--amend ossapps/splitpro-arm64:latest \
110+
111+
docker manifest create \
112+
ossapps/splitpro:$GIT_SHA \
113+
--amend ossapps/splitpro-amd64:$GIT_SHA \
114+
--amend ossapps/splitpro-arm64:$GIT_SHA \
115+
116+
docker manifest create \
117+
ossapps/splitpro:$APP_VERSION \
118+
--amend ossapps/splitpro-amd64:$APP_VERSION \
119+
--amend ossapps/splitpro-arm64:$APP_VERSION \
120+
121+
docker manifest push ossapps/splitpro:latest
122+
docker manifest push ossapps/splitpro:$GIT_SHA
123+
docker manifest push ossapps/splitpro:$APP_VERSION
124+
125+
- name: Create and push Github Container Registry manifest
126+
run: |
127+
APP_VERSION="$(git name-rev --tags --name-only $(git rev-parse HEAD) | head -n 1 | sed 's/\^0//')"
128+
GIT_SHA="$(git rev-parse HEAD)"
129+
130+
docker manifest create \
131+
ghcr.io/oss-apps/splitpro:latest \
132+
--amend ghcr.io/oss-apps/splitpro-amd64:latest \
133+
--amend ghcr.io/oss-apps/splitpro-arm64:latest \
134+
135+
docker manifest create \
136+
ghcr.io/oss-apps/splitpro:$GIT_SHA \
137+
--amend ghcr.io/oss-apps/splitpro-amd64:$GIT_SHA \
138+
--amend ghcr.io/oss-apps/splitpro-arm64:$GIT_SHA \
139+
140+
docker manifest create \
141+
ghcr.io/oss-apps/splitpro:$APP_VERSION \
142+
--amend ghcr.io/oss-apps/splitpro-amd64:$APP_VERSION \
143+
--amend ghcr.io/oss-apps/splitpro-arm64:$APP_VERSION \
144+
145+
docker manifest push ghcr.io/oss-apps/splitpro:latest
146+
docker manifest push ghcr.io/oss-apps/splitpro:$GIT_SHA
147+
docker manifest push ghcr.io/oss-apps/splitpro:$APP_VERSION

Dockerfile.prod

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -67,66 +67,19 @@ _That's when I decided to work on this_
6767
- PostgreSQL
6868
- pnpm (recommended)
6969

70-
## Self Hosting
71-
### Prerequisites
72-
- Docker
73-
- Docker compose plugin
74-
- .env file with all the required secrets and env vars (make sure to uncomment POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD)
70+
## Docker
7571

76-
### Instructions to deploy (it's just one command away)
77-
```bash
78-
docker compose build && docker compose up -d
79-
```
72+
We provide a Docker container for Splitpro, which is published on both DockerHub and GitHub Container Registry.
8073

81-
### Domain setup, SSL certs and reverse proxy
82-
### Prerequisites
83-
- nginx
84-
- certbot
85-
- certbot nginx plugin
86-
#### Nginx Guide for RedHat based systems (Fedora, RHEL, CentOS etc)
87-
Add a new conf file to your nginx configuration for this application
88-
```bash
89-
sudo cp ./splitpro-nginx.conf /etc/nginx/conf.d/
90-
```
91-
Validate the new config
92-
```bash
93-
sudo nginx -t
94-
```
95-
If everything looks good, you can go ahead and restart nginx to reflect the new config (You can also reload it but I prefer restart)
96-
```bash
97-
sudo systemctl restart nginx
98-
```
99-
Now let's install certbot to request a free SSL cert from letsencrypt
100-
```bash
101-
sudo dnf install -y certbot python3-certbot-nginx
102-
```
103-
Request the certificate
104-
```bash
105-
sudo certbot --nginx -d splitpro.domain.com
106-
```
107-
and that's it!
108-
109-
## Setup Backups
110-
### Prerequisites
111-
- mutt (install and configure, see instructions here https://www.makeuseof.com/install-configure-mutt-with-gmail-on-linux/)
112-
- crontab
74+
DockerHub: [https://hub.docker.com/r/ossapps/splitpro](https://hub.docker.com/r/ossapps/splitpro)
11375

114-
Create a folder called as `.bps` in root's home dir
115-
```bash
116-
mkdir /root/.bps
117-
```
76+
GitHub Container Registry: [https://ghcr.io/oss-apps/splitpro](https://ghcr.io/oss-apps/splitpro)
11877

119-
*Update the script.sh to have your own target email address instead of `[email protected]`*
78+
You can pull the Docker image from either of these registries and run it with your preferred container hosting provider.
12079

121-
Copy the backup script into `.bps` location
122-
```bash
123-
cp ./backup/script.sh /root/.bps/
124-
```
80+
Please note that you will need to provide environment variables for connecting to the database, redis, aws and so forth.
12581

126-
Add the cron job in the crontab
127-
```bash
128-
crontab ./backup/crontab.txt
129-
```
82+
For detailed instructions on how to configure and run the Docker container, please refer to the Docker [Docker README](./docker/README.md) in the docker directory.
13083

13184
### Run locally
13285

@@ -137,7 +90,6 @@ crontab ./backup/crontab.txt
13790
- Run `pnpm db:push` or `pnpm prisma:prod` to populate db migrations
13891
- Run `pnpm dev`
13992

140-
14193
## Sponsors
14294

14395
We are grateful for the support of our sponsors.

docker-compose.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

docker/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM node:20.11.1-alpine AS base
2+
ENV SKIP_ENV_VALIDATION="true"
3+
ENV DOCKER_OUTPUT=1
4+
ENV NEXT_TELEMETRY_DISABLED 1
5+
6+
RUN apk add --no-cache libc6-compat
7+
RUN apk update
8+
9+
WORKDIR /app
10+
RUN npm i -g pnpm
11+
RUN ls
12+
COPY package.json pnpm-lock.yaml ./
13+
14+
RUN pnpm install
15+
16+
COPY . .
17+
RUN pnpm generate
18+
RUN pnpm build
19+
20+
FROM node:20-alpine3.19 as release
21+
WORKDIR /app
22+
RUN npm i -g pnpm
23+
24+
RUN apk add --no-cache libc6-compat
25+
RUN apk update
26+
27+
28+
COPY --from=base /app/next.config.js .
29+
COPY --from=base /app/package.json .
30+
COPY --from=base /app/pnpm-lock.yaml .
31+
32+
COPY --from=base /app/.next/standalone ./
33+
COPY --from=base /app/.next/static ./.next/static
34+
COPY --from=base /app/public ./public
35+
36+
COPY --from=base /app/prisma/schema.prisma ./prisma/schema.prisma
37+
COPY --from=base /app/prisma/migrations ./prisma/migrations
38+
COPY --from=base /app/node_modules/prisma ./node_modules/prisma
39+
COPY --from=base /app/node_modules/@prisma ./node_modules/@prisma
40+
COPY --from=base /app/node_modules/sharp ./node_modules/sharp
41+
42+
# Symlink the prisma binary
43+
RUN mkdir node_modules/.bin
44+
RUN ln -s /app/node_modules/prisma/build/index.js ./node_modules/.bin/prisma
45+
46+
# set this so it throws error where starting server
47+
ENV SKIP_ENV_VALIDATION="false"
48+
49+
COPY ./docker/start.sh ./start.sh
50+
51+
CMD ["sh", "start.sh"]

0 commit comments

Comments
 (0)