-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: docker file as non root user (#80)
* build: docker file as non root user * ci: node version
- Loading branch information
Showing
3 changed files
with
33 additions
and
36 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
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,10 +1,37 @@ | ||
FROM nginx | ||
COPY dist /usr/share/nginx/html | ||
RUN rm etc/nginx/conf.d/default.conf | ||
COPY nginx.conf etc/nginx/conf.d/ | ||
# Build environment | ||
FROM node:20-alpine AS build | ||
WORKDIR /app | ||
COPY package.json yarn.lock .env ./ | ||
COPY public ./public | ||
COPY index.html ./ | ||
RUN yarn install --frozen-lockfile --network-timeout 600000 | ||
COPY tsconfig.json .prettierrc vite.config.js ./ | ||
COPY scripts ./scripts | ||
COPY src ./src | ||
RUN yarn build | ||
COPY nginx.conf ./ | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod 755 /entrypoint.sh | ||
# Production Env | ||
FROM nginx:stable-alpine | ||
COPY --from=build /app/nginx.conf /etc/nginx/conf.d/default.conf | ||
WORKDIR /usr/share/nginx/html | ||
|
||
# Add bash | ||
RUN apk add --no-cache bash | ||
|
||
## Copy .env file and shell script to container | ||
COPY --from=build /app/dist ./ | ||
COPY --from=build /app/entrypoint.sh . | ||
RUN chmod 755 entrypoint.sh | ||
|
||
# add non-root user | ||
RUN touch /var/run/nginx.pid | ||
RUN chown -R nginx:nginx /var/run/nginx.pid /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx/conf.d | ||
|
||
# non root users cannot listen on 80 | ||
EXPOSE 8080 | ||
|
||
USER nginx | ||
|
||
ENTRYPOINT [ "/entrypoint.sh" ] | ||
CMD ["nginx", "-g", "daemon off;"] |
This file was deleted.
Oops, something went wrong.