Skip to content

Commit

Permalink
Switch to deploy via Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasename committed Aug 1, 2024
1 parent 04b386b commit c146a04
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9

Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9

Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9

- name: Set up known_hosts file
run: |
mkdir -p ~/.ssh/ && touch ~/.ssh/known_hosts
Expand All @@ -26,8 +18,6 @@ jobs:
with:
ssh-private-key: ${{ secrets.SSH_KEY }}

- name: Install PM2
run: pnpm install -g pm2

- name: Deploy
run: pnpm run deploy
- name: Run deploy script
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'cd ${{ secrets.DEPLOY_PATH }} && ./deploy.sh'
40 changes: 40 additions & 0 deletions .github/workflows/publish-ghcr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish to GHCR
on:
workflow_dispatch:
push:
branches:
- main

jobs:
publish:
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: get-npm-version
id: package-version
uses: martinbeentjes/[email protected]
- 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
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to GHCR
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
ghcr.io/${{ github.repository }}:${{ github.sha }}
ghcr.io/${{ github.repository }}:${{ steps.package-version.outputs.current-version }}
ghcr.io/${{ github.repository }}:latest
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:20-alpine
# Docker builds hang in arm/v7 images, so we use Node 18 to build and Node 20 to run
# Cf. https://github.com/docker/build-push-action/issues/1071
FROM node:18-alpine AS BUILD_IMAGE
WORKDIR /app
RUN apk add --no-cache python3 build-base
ADD package.json pnpm-lock.yaml /app/
Expand All @@ -8,4 +10,10 @@ COPY . /app/
# Always exit 0 here because TSC will fail while we're migrating to TypeScript but
# not everything uses TypeScript
RUN pnpm run build; exit 0

# Now we run the app
FROM node:20-alpine
ENV NODE_ENV=production
WORKDIR /app
COPY --from=BUILD_IMAGE /app ./
CMD ["node", "dist/start.js"]
23 changes: 0 additions & 23 deletions deploy.sh

This file was deleted.

4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ volumes:

services:
gathio:
build: .
container_name: gathio-app
image: ghcr.io/lowercasename/gathio:latest
links:
- mongo
ports:
Expand All @@ -14,6 +15,7 @@ services:
# The path to Gathio's user-uploaded event images folder - change to match your system
- ./gathio-docker/images:/app/public/events
mongo:
container_name: gathio-db
image: mongo:latest
volumes:
- mongodb_data_db:/data/db
28 changes: 21 additions & 7 deletions docs/running-gathio/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ the subject](https://www.linode.com/docs/web-servers/nginx/use-nginx-reverse-pro
## Docker

The easiest way to run Gathio using Docker is by using the provided
`docker-compose` configuration.
`docker-compose` configuration. We provide a Docker image at [GitHub
Container Repository](https://github.com/lowercasename/gathio/pkgs/container/gathio).

Create a directory on your system where you'll keep the Gathio configuration
file and another where Gathio can store user-uploaded event images. Copy the
Expand All @@ -112,19 +113,32 @@ volumes:
```

Adjust any settings in the config file, especially the MongoDB URL, which should
read as follows for the standard Dockerfile config, and the email service if you
read as follows for the standard Docker Compose config, and the email service if you
want to enable it:

```ini
mail_service = "nodemailer"
mongodb_url = "mongodb://mongo:27017/gathio"
mail_service = "nodemailer"
```

You can copy the `docker-compose.yml` file into that same `gathio-docker` directory
you created - you don't need any of the source code. Once you're done, your directory
should look something like this:

```
gathio-docker
├── config
│ └── config.toml
├── docker-compose.yml
└── images
```

Finally, start the Docker stack:
Finally, from wherever you've put your `docker-compose.yml` file, start the Docker stack:

```bash
docker-compose up -d --build
cd gathio-docker
docker-compose up -d
```

Gathio should now be running on `http://localhost:3000`, and storing data in a
Docker volume.
Gathio should now be running on `http://localhost:3000`, storing data in a
Docker volume, and storing images on your filesystem.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"start": "node dist/start.js",
"dev": "nodemon -e ts,js --watch src --exec \"pnpm run build ; pnpm run start\"",
"test:dev": "CYPRESS=true pnpm run dev & wait-on http://localhost:3000 && cypress open --e2e --browser chrome",
"test": "pnpm run build || true && CYPRESS=true pnpm run start & wait-on http://localhost:3000 && cypress run --e2e --browser chrome",
"deploy": "pm2 deploy ecosystem.config.cjs production"
"test": "pnpm run build || true && CYPRESS=true pnpm run start & wait-on http://localhost:3000 && cypress run --e2e --browser chrome"
},
"engines": {
"node": ">=16.16.0"
Expand Down Expand Up @@ -47,6 +46,7 @@
"request": "^2.88.2",
"sanitize-html": "^2.13.0",
"toml": "^3.0.0",
"typescript": "^5.4.5",
"wait-on": "^7.2.0"
},
"devDependencies": {
Expand All @@ -60,7 +60,6 @@
"cypress": "^13.10.0",
"eslint": "^8.57.0",
"nodemon": "^2.0.22",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
"prettier": "^3.2.5"
}
}
}
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c146a04

Please sign in to comment.