Skip to content

Commit 0887d02

Browse files
author
Nikita Filonov
committed
build
1 parent 740e1b3 commit 0887d02

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
build
3+
.git
4+
.gitignore
5+
Dockerfile*
6+
docker-compose*
7+
npm-debug.log
8+
pnpm-lock.yaml
9+
.vscode
10+
.DS_Store
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
docker:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Log in to Docker Hub
17+
uses: docker/login-action@v3
18+
with:
19+
username: ${{ secrets.DOCKER_USERNAME }}
20+
password: ${{ secrets.DOCKER_TOKEN }}
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Build and push
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
push: true
30+
tags: |
31+
${{ secrets.DOCKER_USERNAME }}/load-testing-hub-panel:latest
32+
${{ secrets.DOCKER_USERNAME }}/load-testing-hub-panel:${{ github.ref_name }}

Dockerfile

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,53 @@
1-
FROM node:20-alpine
1+
# ===== Stage 1: Build React application =====
2+
FROM node:20-alpine AS build
23

4+
# Set working directory inside the container
35
WORKDIR /app
46

7+
# Enable corepack (to manage Yarn versions)
8+
RUN corepack enable
9+
10+
# Copy dependency files
511
COPY package.json yarn.lock ./
6-
RUN yarn install --frozen-lockfile
12+
13+
# Install dependencies (frozen lockfile to ensure reproducible builds)
14+
RUN yarn install --frozen-lockfile --non-interactive
15+
16+
# Copy the rest of the application source code
717
COPY . .
18+
19+
# Build-time arguments with default values (can be overridden via --build-arg)
20+
ARG SERVER_URL="http://localhost:8000"
21+
ARG API_VERSION="/api/v1"
22+
ARG DURATION_FORMAT="m[m]s[s]"
23+
ARG API_DATE_FORMAT="YYYY-MM-DD"
24+
ARG API_TIME_FORMAT="HH:mm:ss"
25+
ARG PICKER_DATE_FORMAT="dd.MM.yyyy"
26+
ARG PICKER_TIME_FORMAT="HH:mm"
27+
28+
# Set environment variables for CRA build
29+
ENV REACT_APP_SERVER_URL=${SERVER_URL}
30+
ENV REACT_APP_API_VERSION=${API_VERSION}
31+
ENV REACT_APP_DURATION_FORMAT=${DURATION_FORMAT}
32+
ENV REACT_APP_API_DATE_FORMAT=${API_DATE_FORMAT}
33+
ENV REACT_APP_API_TIME_FORMAT=${API_TIME_FORMAT}
34+
ENV REACT_APP_PICKER_DATE_FORMAT=${PICKER_DATE_FORMAT}
35+
ENV REACT_APP_PICKER_TIME_FORMAT=${PICKER_TIME_FORMAT}
36+
37+
# Build the production version of the React app
838
RUN yarn build
9-
RUN yarn add express express-favicon
1039

11-
EXPOSE 13100
40+
# ===== Stage 2: Serve static files with Nginx =====
41+
FROM nginx:alpine
42+
43+
# Copy custom nginx configuration
44+
COPY nginx.conf /etc/nginx/conf.d/default.conf
45+
46+
# Copy the build output from the previous stage
47+
COPY --from=build /app/build /usr/share/nginx/html
48+
49+
# Expose port 80 for HTTP traffic
50+
EXPOSE 80
51+
52+
# Default command to run Nginx in the foreground
53+
CMD ["nginx", "-g", "daemon off;"]

nginx.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
# Root directory for static files
6+
root /usr/share/nginx/html;
7+
8+
# Handle SPA (Single Page Application) routing
9+
location / {
10+
try_files $uri /index.html;
11+
}
12+
13+
# Static assets: JS, CSS, images, fonts
14+
location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|ico|ttf|woff|woff2)$ {
15+
try_files $uri =404;
16+
access_log off;
17+
18+
# Cache for 1 year, immutable means "content will never change"
19+
expires 1y;
20+
add_header Cache-Control "public, immutable";
21+
}
22+
}

0 commit comments

Comments
 (0)