Skip to content

Commit

Permalink
Add GitHub CI files to publish Docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasename committed Jul 31, 2024
1 parent 04b386b commit 2fbb753
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 18 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
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v4

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

Expand Down
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"]
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.
21 changes: 21 additions & 0 deletions gathio-docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
volumes:
mongodb_data_db:

services:
gathio:
container_name: gathio-app
image: ghcr.io/lowercasename/gathio:latest
links:
- mongo
ports:
- 3000:3000
volumes:
# The path to Gathio's config folder - change to match your system
- ./gathio-docker/config:/app/config
# 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 +61,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 2fbb753

Please sign in to comment.