Skip to content

Commit 4166652

Browse files
author
Zabilsya
committed
[DOP-21434] create docker image and docker ci
1 parent ce5a4c3 commit 4166652

File tree

13 files changed

+218
-39
lines changed

13 files changed

+218
-39
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.git/
2+
.github/
3+
.dockerignore
4+
.gitignore
5+
./docker/Dockerfile
6+
*docker-compose*
7+
8+
.husky/
9+
node_modules/
10+
public/env-config.js
11+
env-config.js
12+
dist/

.github/workflows/ci.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/linters.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Code analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
pull_request:
8+
branches-ignore:
9+
- master
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
linters:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Install modules
23+
run: yarn install --frozen-lockfile
24+
25+
- name: Cache modules
26+
uses: actions/cache@v4
27+
with:
28+
path: ./node_modules
29+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
32+
${{ runner.os }}-yarn-
33+
34+
- name: Run Type check
35+
run: yarn type-check
36+
37+
- name: Run ESLint
38+
run: yarn lint
39+
40+
- name: Run Prettier
41+
run: yarn prettier --check
42+
43+
- name: Build project
44+
run: yarn build

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
tags:
8+
- '[0-9]+.[0-9]+.[0-9]+'
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
release:
17+
name: Build & push frontend image to Dockerhub
18+
runs-on: ubuntu-latest
19+
if: github.repository == 'MobileTeleSystems/syncmaster-ui' # prevent running on forks
20+
21+
steps:
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Login to Docker Hub
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
34+
- name: Checkout code
35+
uses: actions/checkout@v4
36+
37+
- name: Set tag
38+
id: set_tag
39+
run: |
40+
if [[ "${{ github.ref_type }}" == "branch" && "${{ github.ref_name }}" == "develop" ]]; then
41+
echo "TAG=mtsrus/syncmaster-ui:develop" >> $GITHUB_ENV
42+
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
43+
echo "TAG=mtsrus/syncmaster-ui:latest,mtsrus/syncmaster-ui:${{ github.ref_name }}" >> $GITHUB_ENV
44+
fi
45+
46+
- name: Build UI image
47+
uses: docker/build-push-action@v6
48+
with:
49+
tags: ${{ env.TAG }}
50+
context: .
51+
file: ./docker/Dockerfile
52+
target: prod
53+
pull: true
54+
push: true
55+
cache-to: type=inline
56+
cache-from: mtsrus/syncmaster-ui:develop
57+
platforms: |
58+
linux/amd64
59+
linux/arm64/v8
60+
provenance: mode=max
61+
62+
- name: Update DockerHub Description
63+
uses: peter-evans/dockerhub-description@v4
64+
if: github.ref_type == 'tag'
65+
with:
66+
username: ${{ secrets.DOCKERHUB_USERNAME }}
67+
# this requires token with read+write+delete permissions. read+write is not enough!
68+
password: ${{ secrets.DOCKERHUB_TOKEN }}
69+
repository: mtsrus/syncmaster-ui
70+
short-description: ${{ github.event.repository.description }}
71+
enable-url-completion: true

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ yarn-error.log
1717

1818

1919
/**/generated
20-
/**/build
20+
/**/build
21+
22+
public/env-config.js
23+
env-config.js

docker/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM node:23.1.0 AS build
2+
3+
WORKDIR /app
4+
5+
COPY .yarnrc.yml .
6+
COPY .yarn ./.yarn
7+
8+
COPY package.json yarn.lock ./
9+
RUN yarn install --immutable
10+
11+
COPY . .
12+
RUN yarn build
13+
14+
15+
FROM nginx:stable AS prod
16+
17+
WORKDIR /usr/share/nginx/html
18+
19+
COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf
20+
COPY --from=build /app/dist .
21+
22+
COPY ./docker/env.sh env.sh
23+
COPY .env .env
24+
RUN chmod +x env.sh
25+
26+
EXPOSE 3000
27+
28+
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]

docker/env.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Recreate config file
4+
rm -rf env-config.js
5+
touch env-config.js
6+
7+
# Add assignment
8+
echo "window.env = {" >> env-config.js
9+
10+
# Read each line in .env file
11+
# Each line represents key=value pairs
12+
while read -r line || [[ -n "$line" ]];
13+
do
14+
# Split env variables by character `=`
15+
if printf '%s\n' "$line" | grep -q -e '='; then
16+
varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
17+
varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
18+
fi
19+
20+
# Read value of current variable if exists as Environment variable
21+
value=$(printf '%s\n' "${!varname}")
22+
# Otherwise use value from .env file
23+
[[ -z $value ]] && value=${varvalue}
24+
25+
# Append configuration property to JS file
26+
echo " $varname: \"$value\"," >> env-config.js
27+
done < .env
28+
29+
echo "}" >> env-config.js

docker/nginx.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server {
2+
listen 3000;
3+
4+
location / {
5+
root /usr/share/nginx/html;
6+
index index.html index.htm;
7+
try_files $uri $uri/ /index.html;
8+
}
9+
10+
error_page 500 502 503 504 /50x.html;
11+
12+
location = /50x.html {
13+
root /usr/share/nginx/html;
14+
}
15+
16+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Initial settings for react app",
66
"license": "UNLICENSED",
77
"scripts": {
8-
"start": "cross-env NODE_ENV=development webpack serve",
8+
"start": "./docker/env.sh && mkdir -p ./public && cp env-config.js ./public/ && cross-env NODE_ENV=development webpack serve",
99
"start:prod": "cross-env NODE_ENV=production webpack serve",
1010
"build": "rimraf ./dist && cross-env NODE_OPTIONS=--max_old_space_size=8192 && cross-env NODE_ENV=production webpack",
1111
"lint": "eslint .",

src/app/config/router/instance.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { createBrowserRouter } from 'react-router-dom';
2+
import { createBrowserRouter, Navigate } from 'react-router-dom';
33
import { UserDetailPage, UserListPage } from '@pages/user';
44
import { LoginPage } from '@pages/auth';
55
import { AuthLayout, ErrorLayout, PrivateLayout } from '@app/layouts';
@@ -40,6 +40,10 @@ export const router = createBrowserRouter([
4040
</PrivateRoute>
4141
),
4242
children: [
43+
{
44+
path: '/',
45+
element: <Navigate to="/users" replace />,
46+
},
4347
{
4448
path: '/users',
4549
element: <UserListPage />,

0 commit comments

Comments
 (0)