-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted Dockerfile into multi stages
- Loading branch information
1 parent
bc8f651
commit 12ff5b9
Showing
1 changed file
with
32 additions
and
7 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 |
---|---|---|
@@ -1,28 +1,53 @@ | ||
# Stage 1: Build stage with Node setup | ||
FROM node:18-alpine AS build | ||
FROM node:18-alpine as build | ||
|
||
# Copy the source code | ||
COPY ./ /tmp/source_code | ||
|
||
# Install dependencies | ||
RUN cd /tmp/source_code && npm install | ||
|
||
# Build the source code | ||
RUN cd /tmp/source_code && npm run build | ||
|
||
# create libraries directory | ||
RUN mkdir -p /libraries | ||
|
||
# Copy the lib, bin, node_modules, and package.json files to the /libraries directory | ||
RUN cp -r /tmp/source_code/lib /libraries | ||
RUN cp -r /tmp/source_code/node_modules /libraries | ||
RUN cp /tmp/source_code/package.json /libraries | ||
RUN cp /tmp/source_code/package-lock.json /libraries | ||
|
||
# Copy the bin directory to the /libraries directory | ||
RUN cp -r /tmp/source_code/bin /libraries | ||
|
||
# Remove everything inside /tmp | ||
RUN rm -rf /tmp/* | ||
|
||
FROM node:18-alpine | ||
|
||
# Install necessary packages | ||
RUN apk add --no-cache bash git chromium | ||
Check notice Code scanning / SonarCloud Arguments in long RUN instructions should be sorted Low
Sort these package names alphanumerically. See more on SonarCloud
|
||
|
||
# Copy the libraries directory from the build stage | ||
COPY --from=build /libraries /libraries | ||
|
||
# Environment variables for Puppeteer | ||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true | ||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser | ||
|
||
# Copy the asyncapi directory from the build stage | ||
# Assuming you have a build stage, otherwise remove --from=build | ||
COPY /tmp/asyncapi/ /asyncapi | ||
|
||
# Create a non-root user | ||
RUN addgroup -S myuser && adduser -S myuser -G myuser | ||
|
||
# Create a script that runs the desired command | ||
RUN echo -e "#!/bin/bash\n/asyncapi/bin/run_bin" > /usr/local/bin/asyncapi | ||
RUN echo -e "#!/bin/bash\n/libraries/bin/run_bin" > /usr/local/bin/asyncapi | ||
|
||
# Make the script executable | ||
RUN chmod +x /usr/local/bin/asyncapi | ||
|
||
# Change ownership to non-root user | ||
RUN chown -R myuser:myuser /asyncapi /usr/local/bin/asyncapi || echo "Failed to change ownership" | ||
RUN chown -R myuser:myuser /libraries /usr/local/bin/asyncapi || echo "Failed to change ownership" | ||
|
||
# Copy the entrypoint script | ||
COPY github-action/entrypoint.sh /entrypoint.sh | ||
|