forked from hedgedoc/hedgedoc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
496 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
FROM --platform=$BUILDPLATFORM docker.io/library/node:20.7.0-bullseye-slim@sha256:86ed0f70880231adc0fb66c2edbba5de350d8587999e2fe4e1f59c11a4cbb3b4 AS builder | ||
|
||
# Build arguments to change source url, branch or tag | ||
ARG CODIMD_REPOSITORY | ||
ARG HEDGEDOC_REPOSITORY=https://github.com/orange-cloudfoundry/hedgedoc.git | ||
ARG VERSION=master | ||
#necessary on ARM because puppeteer doesn't provide a prebuilt binary | ||
ENV PUPPETEER_SKIP_DOWNLOAD=true | ||
ENV YARN_CACHE_FOLDER=/tmp/.yarn | ||
|
||
# Clone the source and remove git repository but keep the HEAD file | ||
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ | ||
--mount=target=/var/cache/apt,type=cache,sharing=locked \ | ||
apt-get update && \ | ||
apt-get install --no-install-recommends -y git jq ca-certificates python-is-python3 build-essential | ||
RUN git clone --depth 1 --branch "$VERSION" "$HEDGEDOC_REPOSITORY" /hedgedoc | ||
RUN git -C /hedgedoc log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1 | ||
RUN git -C /hedgedoc rev-parse HEAD > /tmp/gitref | ||
RUN rm -rf /hedgedoc/.git/* | ||
RUN mv /tmp/gitref /hedgedoc/.git/HEAD | ||
RUN jq ".repository.url = \"${HEDGEDOC_REPOSITORY}\"" /hedgedoc/package.json > /hedgedoc/package.new.json | ||
RUN mv /hedgedoc/package.new.json /hedgedoc/package.json | ||
|
||
# Install app dependencies and build | ||
WORKDIR /hedgedoc | ||
|
||
RUN --mount=type=cache,sharing=locked,target=/tmp/.yarn yarn install --immutable | ||
RUN yarn run build | ||
|
||
FROM docker.io/library/node:20.7.0-bullseye-slim@sha256:86ed0f70880231adc0fb66c2edbba5de350d8587999e2fe4e1f59c11a4cbb3b4 AS modules-installer | ||
WORKDIR /hedgedoc | ||
|
||
ENV NODE_ENV=production | ||
ENV YARN_CACHE_FOLDER=/tmp/.yarn | ||
|
||
COPY --from=builder /hedgedoc /hedgedoc | ||
|
||
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ | ||
--mount=target=/var/cache/apt,type=cache,sharing=locked \ | ||
apt-get update && \ | ||
apt-get install --no-install-recommends -y git ca-certificates python-is-python3 build-essential | ||
|
||
RUN --mount=type=cache,sharing=locked,target=/tmp/.yarn yarn workspaces focus --production | ||
|
||
FROM docker.io/library/node:20.7.0-bullseye-slim@sha256:86ed0f70880231adc0fb66c2edbba5de350d8587999e2fe4e1f59c11a4cbb3b4 AS app | ||
|
||
LABEL org.opencontainers.image.title='HedgeDoc production image(debian)' | ||
LABEL org.opencontainers.image.url='https://hedgedoc.org' | ||
LABEL org.opencontainers.image.source='https://github.com/hedgedoc/container' | ||
LABEL org.opencontainers.image.documentation='https://github.com/hedgedoc/container/blob/master/README.md' | ||
LABEL org.opencontainers.image.licenses='AGPL-3.0' | ||
|
||
WORKDIR /hedgedoc | ||
|
||
ARG UID=10000 | ||
ENV NODE_ENV=production | ||
ENV UPLOADS_MODE=0700 | ||
|
||
RUN apt-get update && \ | ||
apt-get install --no-install-recommends -y gosu && \ | ||
rm -r /var/lib/apt/lists/* | ||
|
||
# Create hedgedoc user | ||
RUN adduser --uid $UID --home /hedgedoc/ --disabled-password --system hedgedoc | ||
|
||
COPY --chown=$UID --from=modules-installer /hedgedoc /hedgedoc | ||
|
||
# Add configuraton files | ||
COPY ["resources/config.json", "/files/"] | ||
|
||
# Healthcheck | ||
COPY --chown=$UID /resources/healthcheck.mjs /hedgedoc/healthcheck.mjs | ||
HEALTHCHECK --interval=15s CMD node healthcheck.mjs | ||
|
||
# For backwards compatibility | ||
RUN ln -s /hedgedoc /codimd | ||
|
||
# Symlink configuration files | ||
RUN rm -f /hedgedoc/config.json | ||
RUN ln -s /files/config.json /hedgedoc/config.json | ||
|
||
EXPOSE 3000 | ||
|
||
COPY ["resources/docker-entrypoint.sh", "/usr/local/bin/docker-entrypoint.sh"] | ||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] | ||
|
||
CMD ["node", "app.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version: '3' | ||
services: | ||
database: | ||
image: postgres:13.4-alpine | ||
environment: | ||
- POSTGRES_USER=hedgedoc | ||
- POSTGRES_PASSWORD=password | ||
- POSTGRES_DB=hedgedoc | ||
volumes: | ||
- database:/var/lib/postgresql/data | ||
restart: always | ||
app: | ||
# Make sure to use the latest release from https://hedgedoc.org/latest-release | ||
image: quay.io/hedgedoc/hedgedoc:1.9.9 | ||
environment: | ||
- CMD_DB_URL=postgres://hedgedoc:password@database:5432/hedgedoc | ||
- CMD_DOMAIN=localhost | ||
- CMD_URL_ADDPORT=true | ||
volumes: | ||
- uploads:/hedgedoc/public/uploads | ||
ports: | ||
- "3000:3000" | ||
restart: always | ||
depends_on: | ||
- database | ||
volumes: | ||
database: | ||
uploads: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/sh | ||
|
||
# Use gosu if the container started with root privileges | ||
UID="$(id -u)" | ||
[ "$UID" -eq 0 ] && GOSU="gosu hedgedoc" || GOSU="" | ||
|
||
if [ "$HMD_IMAGE_UPLOAD_TYPE" != "" ] && [ "$CMD_IMAGE_UPLOAD_TYPE" = "" ]; then | ||
CMD_IMAGE_UPLOAD_TYPE="$HMD_IMAGE_UPLOAD_TYPE" | ||
fi | ||
|
||
# Print warning if local data storage is used but no volume is mounted | ||
[ "$CMD_IMAGE_UPLOAD_TYPE" = "filesystem" ] && { mountpoint -q ./public/uploads || { | ||
echo " | ||
################################################################# | ||
### ### | ||
### !!!WARNING!!! ### | ||
### ### | ||
### Using local uploads without persistence is ### | ||
### dangerous. You'll loose your data on ### | ||
### container removal. Check out: ### | ||
### https://docs.docker.com/engine/tutorials/dockervolumes/ ### | ||
### ### | ||
### !!!WARNING!!! ### | ||
### ### | ||
################################################################# | ||
"; | ||
} ; } | ||
|
||
# Change owner and permission if filesystem backend is used and user has root permissions | ||
if [ "$UID" -eq 0 ] && [ "$CMD_IMAGE_UPLOAD_TYPE" = "filesystem" ]; then | ||
if [ "$UID" -eq 0 ]; then | ||
echo "Updating uploads directory permissions ($UPLOADS_MODE)" | ||
chown -R hedgedoc ./public/uploads | ||
chmod $UPLOADS_MODE ./public/uploads | ||
find ./public/uploads -type f -executable -exec chmod a-x {} \; | ||
else | ||
echo " | ||
################################################################# | ||
### ### | ||
### !!!WARNING!!! ### | ||
### ### | ||
### Container was started without root permissions ### | ||
### and filesystem storage is being used. ### | ||
### In case of filesystem errors these need to be ### | ||
### changed manually ### | ||
### ### | ||
### !!!WARNING!!! ### | ||
### ### | ||
################################################################# | ||
"; | ||
fi | ||
fi | ||
|
||
# Sleep to make sure everything is fine... | ||
sleep 3 | ||
|
||
# run | ||
exec $GOSU "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import fetch from 'node-fetch' | ||
|
||
// Kill myself after 5 second timeout | ||
setTimeout(() => { | ||
process.exit(1) | ||
}, 5000) | ||
|
||
fetch(`http://localhost:${process.env.CMD_PORT || '3000' }/_health`, {headers: { "user-agent": "hedgedoc-container-healthcheck/1.1"}}).then((response) => { | ||
if (!response.ok) { | ||
process.exit(1) | ||
} | ||
return response.json() | ||
}).then((data) => { | ||
if (!data.ready) { | ||
process.exit(1) | ||
} | ||
process.exit(0) | ||
}).catch(() => { | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[client] | ||
default-character-set=utf8mb4 | ||
|
||
[mysql] | ||
default-character-set=utf8mb4 | ||
|
||
[mysqld] | ||
collation-server = utf8mb4_unicode_ci | ||
init-connect='SET NAMES utf8mb4' | ||
character-set-server = utf8mb4 |
Oops, something went wrong.