Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement best practices in Docker image #1077

Merged
merged 7 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.github
/.husky
/cypress
/demos
.gitignore
.prettierrc
codecov.yml
CODEOWNERS
cypress.json
Jenkinsfile
LICENSE.md
README.md
25 changes: 18 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
# Multipart build dockerfile to build and serve scigateway

FROM node:16.14-alpine3.15 as build

WORKDIR /scigateway
ENV PATH /scigateway/node_modules/.bin:$PATH

# Set Yarn version
COPY package.json tsconfig.json yarn.lock ./

# TODO - Use Yarn 2 when project is upgraded
RUN yarn set version 1.22
RUN yarn set version 1.22 \
# TODO: use yarn install --production:
# https://github.com/ral-facilities/scigateway/issues/1025
&& yarn install

# Install dependancies
# TODO: use yarn install --production:
# https://github.com/ral-facilities/scigateway/issues/1025
COPY . .
RUN yarn install

RUN yarn build

# Put the output of the build into an apache server
FROM httpd:2.4-alpine3.15
WORKDIR /usr/local/apache2/htdocs
COPY --from=build /scigateway/build/. .

RUN apk --no-cache add libcap \
# Privileged ports are permitted to root only by default.
# setcap to bind to privileged ports (80) as non-root.
&& setcap 'cap_net_bind_service=+ep' /usr/local/apache2/bin/httpd \
# Change access righs for logs from root to www-data
&& chown www-data:www-data /usr/local/apache2/logs

# Switch to non-root user defined in httpd image
USER www-data