diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c76f282930e880e0b9c7da5d36dae4cba26417c..1aa583b49208a9e354a2b365c2a1d9cdb9810513 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,27 @@ -image: node:latest - variables: CONTAINER_IMAGE: 'registry.kszk.bme.hu/kszk/devteam/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME' stages: + - Pre Build - Docker Build +PreBuild: + stage: Pre Build + tags: [docker] + image: node:latest + script: + - npm install + - npm run build + cache: + paths: + - build/ + artifacts: + expire_in: 1 day + paths: + - build/ + only: + - tags + Docker build: stage: Docker Build tags: [docker] diff --git a/Dockerfile b/Dockerfile index 04857eff491235a4ee8cb37ff11cef5c9959137b..8647bbdd6ed187511458d9cea2a087add410f84f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,9 @@ -FROM node:10-alpine +FROM nginx:1.19.2 -WORKDIR /opt/app -ENV TZ Europe/Budapest -RUN apk add --no-cache tzdata && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +# copy the files builded with npm run build +COPY build /var/www +COPY nginx.conf /etc/nginx/nginx.conf -# Copying application files -COPY ./src ./src -COPY ./public ./public -COPY package.json package-lock.json ./ - -# Installing dependencies -RUN npm install -RUN npm install serve - -# Running EXPOSE 3000 -ENTRYPOINT ["npm", "run", "deploy"] +ENTRYPOINT ["nginx","-g","daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..70e322042a5333029b0a8ef90ede6a7577044c4a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,61 @@ +# auto detects a good number of processes to run +worker_processes auto; + +#Provides the configuration file context in which the directives that affect connection processing are specified. +events { + # Sets the maximum number of simultaneous connections that can be opened by a worker process. + worker_connections 8000; + # Tells the worker to accept multiple connections at a time + multi_accept on; +} + + +http { + # what times to include + include /etc/nginx/mime.types; + # what is the default one + default_type application/octet-stream; + + # Sets the path, format, and configuration for a buffered log write + log_format compression '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $upstream_addr ' + '"$http_referer" "$http_user_agent"'; + + server { + # listen on port 80 + listen 3000; + # save logs here + access_log /var/log/nginx/access.log compression; + + # where the root here + root /var/www; + # what file to server as index + index index.html index.htm; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to redirecting to index.html + try_files $uri $uri/ /index.html; + } + + # Media: images, icons, video, audio, HTC + location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { + expires 1M; + access_log off; + add_header Cache-Control "public"; + } + + # Javascript and CSS files + location ~* \.(?:css|js)$ { + try_files $uri =404; + expires 1y; + access_log off; + add_header Cache-Control "public"; + } + + # Any route containing a file extension (e.g. /devicesfile.js) + location ~ ^.+\..+$ { + try_files $uri =404; + } + } +} diff --git a/package.json b/package.json index 55fee579143e53a198731827d7d58bc94067b733..3ebf8e5a2b7b46f5bf28015e2745a7b62959d41f 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,7 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject", - "deploy": "serve -l 3000 -s build" + "eject": "react-scripts eject" }, "devDependencies": { "eslint": "6.8.0",