working couchdb reverse proxy behind webapp binary.

working dockerfile and dockercompose file
added s6-overlay to base image, built ontop of couchdb now.
Bootstrapping of couchdb now creates _users and other system databases.
This commit is contained in:
Jason Kulatunga 2022-10-09 11:08:23 -07:00
parent a7daae9047
commit fcb9d6b31f
7 changed files with 89 additions and 4 deletions

View File

@ -1,3 +1,6 @@
#########################################################################################################
# Frontend Build
#########################################################################################################
FROM node:18.9.0 as frontend-build
WORKDIR /usr/src/fastenhealth/frontend
#COPY frontend/package.json frontend/yarn.lock ./
@ -8,6 +11,9 @@ RUN yarn config set registry "http://registry.npmjs.org" \
COPY frontend/ ./
RUN yarn run build -- --configuration sandbox --output-path=../dist
#########################################################################################################
# Backend Build
#########################################################################################################
FROM golang:1.18 as backend-build
WORKDIR /go/src/github.com/fastenhealth/fastenhealth-onprem
COPY . .
@ -26,12 +32,29 @@ RUN mkdir -p /opt/fasten/db \
&& curl -o /opt/fasten/db/fasten.db -L https://github.com/fastenhealth/testdata/raw/main/fasten.db
#########################################################################################################
# Distribution Build
#########################################################################################################
FROM couchdb:3.2
ARG S6_ARCH=amd64
RUN curl https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-${S6_ARCH}.tar.gz -L -s --output /tmp/s6-overlay-${S6_ARCH}.tar.gz \
&& tar xzf /tmp/s6-overlay-${S6_ARCH}.tar.gz -C / \
&& rm -rf /tmp/s6-overlay-${S6_ARCH}.tar.gz
COPY /docker/couchdb/local.ini /opt/couchdb/etc/
COPY /docker/rootfs /
FROM gcr.io/distroless/static-debian11
WORKDIR /opt/fasten/
COPY --from=backend-build /opt/fasten/ /opt/fasten/
COPY --from=frontend-build /usr/src/fastenhealth/dist /opt/fasten/web
COPY --from=backend-build /go/bin/fasten /opt/fasten/fasten
COPY LICENSE.md /opt/fasten/LICENSE.md
COPY config.yaml /opt/fasten/config/config.yaml
CMD ["/opt/fasten/fasten", "start", "--config", "/opt/fasten/config/config.yaml"]
ENTRYPOINT ["/init"]

View File

@ -2,13 +2,15 @@ version: "3.9"
services:
couchdb:
build:
context: ./docker/couchdb
context: .
dockerfile: Dockerfile
# environment:
# - COUCHDB_USER=admin
# - COUCHDB_PASSWORD=password
ports:
- "9090:8080"
- "5984:5984"
volumes:
- ./.couchdb/data:/opt/couchdb/data
- ./.couchdb/config:/opt/couchdb/etc/local.d
# - ./config.example.yaml:/opt/fasten/config/config.yaml

View File

@ -1,3 +1,15 @@
#########################################################################################################
# CouchDB Build
# NOTE: the context for this build should be the root of the repository.
#########################################################################################################
FROM couchdb:3.2
COPY local.ini /opt/couchdb/etc/
ARG S6_ARCH=amd64
RUN curl https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-${S6_ARCH}.tar.gz -L -s --output /tmp/s6-overlay-${S6_ARCH}.tar.gz \
&& tar xzf /tmp/s6-overlay-${S6_ARCH}.tar.gz -C / \
&& rm -rf /tmp/s6-overlay-${S6_ARCH}.tar.gz
COPY /docker/couchdb/local.ini /opt/couchdb/etc/
COPY /docker/rootfs /
ENTRYPOINT ["/init"]

View File

@ -0,0 +1,7 @@
#!/usr/bin/with-contenv bash
if [ -n "${TZ}" ]
then
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone
fi

View File

@ -0,0 +1,30 @@
#!/usr/bin/with-contenv bash
if [ -f "/opt/couchdb/data/.init_complete" ]; then
echo "Couchdb initialization has already completed, skipping"
else
# start couchdb as a background process (store PID)
echo "Couchdb initialization: start couchdb in background mode"
/opt/couchdb/bin/couchdb &
COUCHDB_PID=$!
# wait for couchdb to be ready
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:5984/_up); do echo "couchdb not ready" && sleep 5; done
# create couch_peruser required system databases manually on startup
echo "couchdb ready, start creating system databases"
curl -X PUT http://127.0.0.1:5984/_users
curl -X PUT http://127.0.0.1:5984/_replicator
curl -X PUT http://127.0.0.1:5984/_global_changes
echo "system databases created successfully"
# gracefully stop couchdb process
echo "killing couchdb process"
kill -2 $COUCHDB_PID
# create the init complete flag
echo "Couchdb initialization: complete"
touch /opt/couchdb/data/.init_complete
fi

View File

@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash
echo "starting couchdb"
/docker-entrypoint.sh /opt/couchdb/bin/couchdb

View File

@ -0,0 +1,7 @@
#!/usr/bin/with-contenv bash
# wait for couchdb to be ready
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:5984/_up); do echo "couchdb not ready" && sleep 5; done
echo "starting fasten"
/opt/fasten/fasten start --config /opt/fasten/config/config.yaml