|
1 | | -# Stage 1: Build stage with Node setup |
2 | | -FROM node:18-alpine as build |
| 1 | +# Stage 1: Build |
| 2 | +FROM node:20-alpine AS build |
| 3 | +WORKDIR /app |
3 | 4 |
|
4 | | -# Copy the source code |
5 | | -COPY ./ /tmp/source_code |
| 5 | +# Copy package files first for better caching |
| 6 | +COPY package*.json ./ |
6 | 7 |
|
7 | | -# Install dependencies |
8 | | -RUN cd /tmp/source_code && npm install --ignore-scripts |
| 8 | +# Install all dependencies (including dev dependencies for build) |
| 9 | +RUN npm ci --ignore-scripts |
9 | 10 |
|
10 | | -# Build the source code |
11 | | -RUN cd /tmp/source_code && npm run build |
| 11 | +# Copy only necessary files for build |
| 12 | +COPY src/ ./src/ |
| 13 | +COPY assets/ ./assets/ |
| 14 | +COPY scripts/ ./scripts/ |
| 15 | +COPY bin/ ./bin/ |
| 16 | +COPY tsconfig.json ./ |
12 | 17 |
|
13 | | -# create libraries directory |
14 | | -RUN mkdir -p /libraries |
| 18 | +# Build the application |
| 19 | +RUN npm run build && \ |
| 20 | + npm prune --omit=dev && \ |
| 21 | + rm -rf test docs .git tmp node_modules/.cache |
15 | 22 |
|
16 | | -# Copy the lib, bin, node_modules, and package.json files to the /libraries directory |
17 | | -RUN cp -r /tmp/source_code/lib /libraries |
18 | | -RUN cp -r /tmp/source_code/assets /libraries |
19 | | -RUN cp /tmp/source_code/package.json /libraries |
20 | | -RUN cp /tmp/source_code/package-lock.json /libraries |
21 | | -RUN cp /tmp/source_code/oclif.manifest.json /libraries |
22 | | - |
23 | | -# Copy the bin directory to the /libraries directory |
24 | | -RUN cp -r /tmp/source_code/bin /libraries |
25 | | - |
26 | | -# Remove everything inside /tmp |
27 | | -RUN rm -rf /tmp/* |
28 | | - |
29 | | -FROM node:18-alpine |
| 23 | +# Stage 2: Runtime |
| 24 | +FROM node:20-alpine |
30 | 25 |
|
31 | 26 | # Install necessary packages |
32 | | -RUN apk add --no-cache bash git |
33 | | - |
34 | | -# Copy the libraries directory from the build stage |
35 | | -COPY --from=build /libraries /libraries |
36 | | - |
37 | | -RUN cd /libraries && npm install --production --ignore-scripts |
38 | | - |
39 | | -# Create a non-root user |
40 | | -# RUN addgroup -S myuser && adduser -S myuser -G myuser |
| 27 | +RUN apk update && apk add --no-cache bash git && rm -rf /var/cache/apk/* |
41 | 28 |
|
42 | | -# Create a script that runs the desired command |
43 | | -RUN ln -s /libraries/bin/run_bin /usr/local/bin/asyncapi |
| 29 | +WORKDIR /app |
44 | 30 |
|
45 | | -# Make the script executable |
46 | | -RUN chmod +x /usr/local/bin/asyncapi |
| 31 | +# Copy built application from build stage |
| 32 | +COPY --from=build /app ./ |
47 | 33 |
|
48 | | -# Change ownership to non-root user |
49 | | -# RUN chown -R myuser:myuser /libraries /usr/local/bin/asyncapi || echo "Failed to change ownership" |
| 34 | +# Create symlink for global access |
| 35 | +RUN ln -s /app/bin/run_bin /usr/local/bin/asyncapi && \ |
| 36 | + chmod +x /usr/local/bin/asyncapi |
50 | 37 |
|
51 | 38 | # Copy the entrypoint script |
52 | 39 | COPY github-action/entrypoint.sh /entrypoint.sh |
|
0 commit comments