Skip to content

Commit

Permalink
chore: fix docker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn authored Dec 30, 2024
1 parent a38bf6f commit 57f34c0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WORKDIR /usr/src/pylon
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json package-lock.json /temp/dev/

RUN cd /temp/dev && npm ci

# install with --production (exclude devDependencies)
Expand All @@ -24,6 +25,8 @@ RUN cd /temp/prod && npm ci --only=production
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
# Run this so that pylon can pick up the prisma types
RUN npx prisma generate

# [optional] tests & build
ENV NODE_ENV=production
Expand All @@ -35,11 +38,17 @@ RUN npm run build

# copy production dependencies and source code into final image
FROM base AS release
# Install openssl and git
RUN apk update && apk add openssl
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/pylon/.pylon .pylon
COPY --from=prerelease /usr/src/pylon/package.json .
COPY --from=prerelease /usr/src/pylon/prisma prisma

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

# run the app
USER node
EXPOSE 3000/tcp
ENTRYPOINT [ "node", "/usr/src/pylon/.pylon/index.js" ]
EXPOSE 3000
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "node", "/usr/src/pylon/.pylon/index.js" ]
29 changes: 29 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# Function to log and run a command
run_command() {
echo "Running: $1"
eval $1
if [ $? -eq 0 ]; then
echo "Success: $1"
else
echo "Failed: $1"
exit 1
fi
}

# Log the start time
echo "Script started at: $(date)"

# Run the commands with logging
run_command "npx prisma generate"
run_command "npx prisma migrate deploy"

# Log the end time
echo "Script ended at: $(date)"

# Switch the user to the node user
su - node

# Execute any additional commands passed to the script
exec "$@"

0 comments on commit 57f34c0

Please sign in to comment.