Skip to content

Commit 6dd7be5

Browse files
committed
Split dockerfiles to dev, prod and test
1 parent 13f5328 commit 6dd7be5

File tree

5 files changed

+162
-12
lines changed

5 files changed

+162
-12
lines changed

Docker/dev.Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:14
2+
3+
ENV USERNAME timetracker
4+
ENV HOME /home/${USERNAME}
5+
RUN useradd -ms /bin/bash ${USERNAME}
6+
7+
WORKDIR ${HOME}/time-tracker-ui
8+
COPY . .
9+
# RUN rm -f .env
10+
# COPY .env .
11+
RUN chown ${USERNAME}:${USERNAME} -R ${HOME}/time-tracker-ui
12+
RUN chmod -R 777 ${HOME}/time-tracker-ui
13+
14+
USER ${USERNAME}
15+
RUN npm cache clean --force && npm install
16+
EXPOSE 4200
17+
EXPOSE 9876
18+
CMD npm run config && ${HOME}/time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck

Docker/prod.Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM node:14 AS development
2+
3+
ENV USERNAME timetracker
4+
ENV HOME /home/${USERNAME}
5+
RUN useradd -ms /bin/bash ${USERNAME}
6+
WORKDIR ${HOME}/time-tracker-ui
7+
COPY . .
8+
# RUN rm -f .env
9+
RUN chown ${USERNAME}:${USERNAME} -R ${HOME}/time-tracker-ui
10+
RUN chmod -R 777 ${HOME}/time-tracker-ui
11+
12+
USER ${USERNAME}
13+
RUN npm cache clean --force && npm install
14+
# EXPOSE 4200
15+
# EXPOSE 9876
16+
# CMD npm run config && ${HOME}/time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck
17+
18+
FROM development as build
19+
COPY .env .
20+
RUN npm run config && npm run build
21+
22+
FROM nginx:1.21 AS production
23+
24+
ENV USERNAME app
25+
RUN useradd -ms /bin/bash ${USERNAME}
26+
27+
COPY nginx.conf /etc/nginx/conf.d/default.conf
28+
COPY --from=build /home/timetracker/time-tracker-ui/dist/time-tracker /usr/share/nginx/html
29+
COPY .env /usr/share/nginx/html
30+
RUN chown -R ${USERNAME}:${USERNAME} /var/cache/nginx && \
31+
chown -R ${USERNAME}:${USERNAME} /var/log/nginx && \
32+
chown -R ${USERNAME}:${USERNAME} /etc/nginx/conf.d
33+
RUN touch /var/run/nginx.pid && chown -R ${USERNAME}:${USERNAME} /var/run/nginx.pid
34+
35+
# FIXME: Actually if we can deploy to azure in port 80 we need a root user
36+
# Maybe we can refactor this dockerfile to use root user directly this is not a good approach y
37+
# security terms. It's a good practice to have rootless in containers so for this
38+
# we can to refactor this dockerfile and the terraform module to deploy in other ports because
39+
# Ports below 1024 needs root permisions.
40+
41+
# USER ${USERNAME}
42+
43+
EXPOSE 80

Docker/test.Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM node:14 AS development
2+
3+
ENV USERNAME timetracker
4+
ENV HOME /home/${USERNAME}
5+
ENV CHROME_BIN /opt/google/chrome/google-chrome
6+
#Essential tools and xvfb
7+
RUN apt-get update && apt-get install -y \
8+
software-properties-common \
9+
unzip \
10+
curl \
11+
wget \
12+
xvfb
13+
14+
#Chrome browser to run the tests
15+
ARG CHROME_VERSION=65.0.3325.181
16+
RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add \
17+
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
18+
&& dpkg -i google-chrome-stable_current_amd64.deb || true
19+
RUN apt-get install -y -f \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
#Disable the SUID sandbox so that chrome can launch without being in a privileged container
23+
RUN dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /opt/google/chrome/google-chrome \
24+
&& echo "#! /bin/bash\nexec /opt/google/chrome/google-chrome.real --no-sandbox --disable-setuid-sandbox \"\$@\"" > /opt/google/chrome/google-chrome \
25+
&& chmod 755 /opt/google/chrome/google-chrome
26+
27+
#Chrome Driver
28+
ARG CHROME_DRIVER_VERSION=2.37
29+
RUN mkdir -p /opt/selenium \
30+
&& curl http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -o /opt/selenium/chromedriver_linux64.zip \
31+
&& cd /opt/selenium; unzip /opt/selenium/chromedriver_linux64.zip; rm -rf chromedriver_linux64.zip; ln -fs /opt/selenium/chromedriver /usr/local/bin/chromedriver;
32+
33+
RUN useradd -ms /bin/bash ${USERNAME}
34+
35+
WORKDIR ${HOME}/time-tracker-ui
36+
COPY . .
37+
RUN rm -f .env
38+
RUN chown ${USERNAME}:${USERNAME} -R ${HOME}/time-tracker-ui
39+
RUN chmod -R 777 ${HOME}/time-tracker-ui
40+
41+
USER ${USERNAME}
42+
RUN npm cache clean --force && npm install
43+
EXPOSE 4200
44+
EXPOSE 9876
45+
CMD npm run config && npm run test

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ help: ## Show this help message.
99
@grep --no-filename -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
1010
sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1111

12-
.PHONY: build
13-
build: ## Create docker image with dependencies needed for development.
14-
docker-compose build
12+
.PHONY: build_dev
13+
build_dev: ## Create docker image with dependencies needed for development.
14+
docker-compose build timetracker_ui_dev
1515

1616
.PHONY: cleanup
1717
cleanup: ## Delete image timetracker_ui
1818
docker rmi timetracker_ui
1919

2020
.PHONY: run
21-
run: ## Execute timetracker_ui docker containe.
22-
docker-compose up -d
21+
run: ## Execute timetracker_ui dev docker containe.
22+
docker-compose up -d timetracker_ui_dev
2323

2424
.PHONY: logs
2525
logs: ## Show logs of timetracker_ui.
@@ -55,11 +55,11 @@ publish: require-acr-arg require-image_tag-arg ## Upload a docker image to the s
5555

5656
.PHONY: build_prod
5757
build_prod: ## Create docker image with dependencies needed for production.
58-
docker build --target production -t timetracker_ui_prod -f Dockerfile .
58+
docker-compose build timetracker_ui_prod
5959

6060
.PHONY: run_prod
6161
run_prod: ## Execute timetracker_ui_prod docker container.
62-
docker run -d -p 4200:4200 --name timetracker_ui_prod timetracker_ui_prod
62+
docker run -d -p 80:80 --env-file ./.env --name timetracker_ui_prod timetracker_ui_prod
6363

6464
.PHONY: stop_prod
6565
stop_prod: ## Stop container timetracker_ui_prod.

docker-compose.yml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,56 @@
11
version: '3.9'
22
services:
3-
time-tracker-ui:
4-
container_name: timetracker_ui
5-
image: timetracker_ui
3+
timetracker_ui_dev:
4+
container_name: timetracker_ui_dev
5+
image: timetracker_ui_dev
66
build:
7-
target: development
87
context: .
9-
dockerfile: ./Dockerfile
8+
dockerfile: ./Docker/dev.Dockerfile
9+
ports:
10+
- 4200:4200
11+
- 9876:9876
12+
environment:
13+
CHROME_BIN: /opt/google/chrome/google-chrome
14+
AUTHORITY: ${AUTHORITY}
15+
CLIENT_ID: ${CLIENT_ID}
16+
SCOPES: ${SCOPES}
17+
STACK_EXCHANGE_ID: ${STACK_EXCHANGE_ID}
18+
STACK_EXCHANGE_ACCESS_TOKEN: ${STACK_EXCHANGE_ACCESS_TOKEN}
19+
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${AZURE_APP_CONFIGURATION_CONNECTION_STRING}
20+
AUTHORITY_JSON: ${AUTHORITY_JSON}
21+
CLIENT_ID_JSON: ${CLIENT_ID_JSON}
22+
SCOPES_JSON: ${SCOPES_JSON}
23+
24+
25+
timetracker_ui_prod:
26+
container_name: timetracker_ui_prod
27+
image: timetracker_ui_prod
28+
build:
29+
# target: production
30+
context: .
31+
dockerfile: ./Docker/prod.Dockerfile
32+
ports:
33+
- 4200:4200
34+
- 9876:9876
35+
environment:
36+
CHROME_BIN: /opt/google/chrome/google-chrome
37+
AUTHORITY: ${AUTHORITY}
38+
CLIENT_ID: ${CLIENT_ID}
39+
SCOPES: ${SCOPES}
40+
STACK_EXCHANGE_ID: ${STACK_EXCHANGE_ID}
41+
STACK_EXCHANGE_ACCESS_TOKEN: ${STACK_EXCHANGE_ACCESS_TOKEN}
42+
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${AZURE_APP_CONFIGURATION_CONNECTION_STRING}
43+
AUTHORITY_JSON: ${AUTHORITY_JSON}
44+
CLIENT_ID_JSON: ${CLIENT_ID_JSON}
45+
SCOPES_JSON: ${SCOPES_JSON}
46+
47+
timetracker_ui_test:
48+
container_name: timetracker_ui_test
49+
image: timetracker_ui_test
50+
build:
51+
# target: production
52+
context: .
53+
dockerfile: ./Docker/test.Dockerfile
1054
ports:
1155
- 4200:4200
1256
- 9876:9876

0 commit comments

Comments
 (0)