Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docker image generation in Dockerfile #5

Merged
merged 1 commit into from
Apr 6, 2021
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist/
/npm-debug.log*
/package-lock.json
/yarn-error.log
/lerna-debug.log
/lerna-debug.log
/Dockerfile-dev
24 changes: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
FROM node:alpine as builder

RUN apk add --no-cache make gcc g++ python git
RUN git clone https://github.com/droppy-js/droppy /droppy
RUN rm -rf /droppy/node_modules && \
cd /droppy && \
yarn && \
yarn bootstrap

FROM node:alpine
LABEL maintainer="https://github.com/droppy-js/droppy"

# Copy files
COPY ["node_modules", "/droppy/node_modules"]
COPY ["packages/client", "/droppy/client"]
COPY ["packages/server", "/droppy/server"]
COPY ["packages/cli", "/droppy/cli"]
COPY ["dist", "/droppy/dist"]
COPY ["droppy.js", "docker-start.sh", "README.md", "LICENSE", "package.json", "/droppy/"]
COPY --from=builder ["/droppy/node_modules", "/droppy/node_modules"]
COPY --from=builder ["/droppy/packages/client", "/droppy/client"]
COPY --from=builder ["/droppy/packages/server", "/droppy/server"]
COPY --from=builder ["/droppy/packages/cli", "/droppy/cli"]
COPY --from=builder ["/droppy/docker-start.sh", "/droppy/README.md", "/droppy/LICENSE", "/droppy/"]

# Install build dependencies and and build modules
RUN cd /droppy && \
find /droppy -type d -exec chmod 0755 {} + && \
find /droppy -type f -exec chmod 0644 {} + && \
chmod 0755 /droppy/docker-start.sh && \
chmod 0755 /droppy/droppy.js && \
mkdir -p /root/.droppy && \
ln -s /config /root/.droppy/config && \
ln -s /files /root/.droppy/files && \
ln -s /droppy/droppy.js /usr/bin/droppy && \
rm -rf \
/root/.config \
/root/.node-gyp \
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ jquery:
cat /tmp/jquery/dist/jquery.min.js | perl -pe 's|"3\..+?"|"3"|' > $(CURDIR)/client/jquery-custom.min.js
rm -rf /tmp/jquery

Dockerfile-dev: Dockerfile
cat Dockerfile | sed -e 's/^RUN git clone.*/COPY [ ".", "\/droppy" ]/' > Dockerfile-dev

docker-dev: Dockerfile-dev
docker build -t localhost/local/droppy-dev -f Dockerfile-dev .

patch: test build ver-patch docker publish
minor: test build ver-minor docker publish
major: test build ver-major docker publish
Expand Down
13 changes: 11 additions & 2 deletions docker-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@

# echo >> /etc/xxx and not adduser/addgroup because adduser/addgroup
# won't work if uid/gid already exists.
echo -e "droppy:x:${UID}:${GID}:droppy:/droppy:/bin/false\n" >> /etc/passwd
echo -e "droppy:x:${UID}:${GID}:droppy:/home/droppy:/bin/false\n" >> /etc/passwd
echo -e "droppy:x:${GID}:droppy\n" >> /etc/group

# it's better to do that (mkdir and chown) here than in the Dockerfile
# because it will be executed even on volumes if mounted.
mkdir -p /config
mkdir -p /files

mkdir -p /home/droppy/.droppy

ln -s /config /home/droppy/.droppy/config
ln -s /files /home/droppy/.droppy/files

chown -R droppy:droppy /home/droppy

chown -R droppy:droppy /config
chown droppy:droppy /files

exec /bin/su -p -s "/bin/sh" -c "exec /usr/bin/droppy start --color -f /files -c /config" droppy
export HOME=/home/droppy

exec /bin/su -l -p -s "/bin/sh" -c "exec node /droppy/cli/lib/cli.js start" droppy