Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.DS_Store
node_modules
/dist

config/config.js
config/internalConfig.json
config/sources/
config/user/

logs/

docker/.env
docker/volumes/

# local env files
.env
.env.local
.env.*.local
.envrc

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ docker/.env
docker/volumes/

# local env files
.envrc
.env
.env.local
.env.*.local
Expand Down
38 changes: 38 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml

# Build a Docker image with CI/CD and push to the GitLab registry.
# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
#
# This template uses one generic job with conditional builds
# for the default branch and all other (MR) branches.

docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# STAGE: INSTALL DEPENDENCIES
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
#RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm i

# STAGE: BUILD ARTIFACTS
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
COPY config/config.example.js ./config/config.js
RUN npm run build

# STAGE: RUN
FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

#RUN addgroup --system --gid 5001 nodejs
#RUN adduser --system --uid 5001 nodejs
USER node

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY . .


VOLUME ['/app/logs', '/app/config']
EXPOSE 3000

ENV PORT 3000

CMD ["node", "server/index.js"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ See all the cron schedules at once, which makes it easier to not overlap them:
![See all the cron schedules at once](https://user-images.githubusercontent.com/366538/141699270-975690d3-7bea-46d7-a8ad-83813a5298f4.png)

## How do I use it?
### Docker

You can run this in docker with
```shell
docker run --init -v ${PWD}/absolute/path/to/config.js:/app/config/config.js -p 4000:4000 ckeeney/openresync
```

See our [Docker guide](docs/docker.md) for a more information on running this using docker and docker-compose.

### Natively
Install the app, configure it, build it, start the back-end server (and optionally start the dev web server), and visit the local website that runs. These are described in the following steps.

### Installation
Expand Down
78 changes: 78 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Docker

This project is published on Docker Hub at [`ckeeney/openresync`](https://hub.docker.com/repository/docker/ckeeney/openresync).

A [config file](https://github.com/tylercollier/openresync#configuration) must be mounted into the container at `/app/config/config.js`. If you mount a whole directory at `/app/config/`, you will have easy access to the files written to `/app/config` by [`openresync`](https://github.com/tylercollier/openresync). Additionally, you can mount a directory at `/app/logs` to have easy access to the [`openresync`](https://github.com/tylercollier/openresync) logs.

## Permissions
By default, the node process runs as the `node` user, with `UID = 1000` and `GID = 1000`. The container-user running the process must have write-access to the files and folders mounted into the container. This can be accomplished in at least two ways:

### 1. Change user that runs the node process
Changing the user that runs the node process to match your host user ensures you can still easily edit the config file without juggling permissions.

First find your own `UID` and `GID`:
```shell
echo $UID : $GID
1000 : 1001
```

Tell docker or `docker-compose` to use these UID and GID to run the process. With docker, you can do this by adding `-u 1000:1001` to your run command. With `docker-compose`, add a `user: 1000:1001` property to the service.

### 2. Change ownership on the host
On the host, you can run
```shell
chown -R ./volumes/openresync/config 1000:1000
```

You may lose write access to the config file if you do this.

If `UID` or `GID` 1000 exist on your host machine, you will see the username and groupname that have `ID = 1000`.

If you do not have a user or group on your machine with `ID = 1000`, you will just see `1000:1000` as the owner of the files and directories.


## Example docker-compose
```yaml
version: '3.7'
openresync:
image: ckeeney/openresync
restart: always

# properly handles kernel signals for faster restarts and shutdowns.
# see https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
init: true

# run as my UID/GID
user: 1000:1001

# expose web service
ports:
- 4000:4000
# pass in some data to my own config file
environment:
TRESTLE_CLIENT_ID: <SECRET>
TRESTLE_CLIENT_SECRET: <SECRET>
DB_CONN_STRING_TRESTLE: mysql://devuser:devpass@mysql:3306/re-data
DB_CONN_STRING_STATS: mysql://devuser:devpass@mysql:3306/re-data

# mount the directories
volumes:
- ./volumes/openresync/config:/app/config
- ./volumes/openresync/logs:/app/logs
depends_on:
- mysql

# any db provider
mysql:
image: mysql:8.0
restart: always
ports:
- 3306:3306
environment:
MYSQL_RANDOM_ROOT_PASSWORD: yespls
MYSQL_DATABASE: re-data
MYSQL_USER: devuser
MYSQL_PASSWORD: devpass
volumes:
- ./volumes/mysql:/var/lib/mysql
```