Skip to content

Commit

Permalink
Converted Dockerfile into multi stages
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatnema committed Oct 5, 2024
1 parent bc8f651 commit 12ff5b9
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions github-action/Dockerfile
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
Expand Down

0 comments on commit 12ff5b9

Please sign in to comment.