Skip to content

Commit eb76bb0

Browse files
ZabilsyaZabilsya
andauthored
[DOP-21434] create docker image and docker ci (#43)
Co-authored-by: Zabilsya <[email protected]>
1 parent ce5a4c3 commit eb76bb0

File tree

12 files changed

+197
-38
lines changed

12 files changed

+197
-38
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/entrypoint.sh /entrypoint.sh
23+
RUN chmod +x /entrypoint.sh
24+
25+
EXPOSE 3000
26+
27+
ENTRYPOINT ["/entrypoint.sh"]
28+
CMD ["nginx", "-g", "daemon off;"]

docker/entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
cat <<EOF > /usr/share/nginx/html/env-config.js
4+
window.env = {
5+
API_URL: "${API_URL}",
6+
};
7+
EOF
8+
9+
exec "$@"

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+
}

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 />,

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
66
<meta name="viewport" content="width=device-width, initial-scale=1"/>
77
<title>SyncMaster</title>
8+
<script src="env-config.js"></script>
89
</head>
910
<body>
1011
<div id="root"></div>

0 commit comments

Comments
 (0)