Skip to content

Commit

Permalink
feat: deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
DuDa369 committed Jul 3, 2024
1 parent 67fa444 commit 90afdf7
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 80 deletions.
84 changes: 48 additions & 36 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
name: .NET

on:
push:
branches: ["main", "controllers", "deploy"]
pull_request:
branches: ["main", "controllers", "deploy"]

jobs:
build:
env:
ASPNETCORE_ENVIRONMENT: "Development"
runs-on: self-hosted

steps:
- name: Checkout repository
uses: actions/checkout@v4 # Check out the code from the repository

- name: Setup .NET
uses: actions/setup-dotnet@v4 # Set up the .NET SDK
with:
dotnet-version: 8.0.x # Specify the exact .NET SDK version

- name: Restore dependencies
run: dotnet restore ./backend # Restore project dependencies

- name: Test
run: dotnet test --verbosity normal ./backend # Run tests

- name: Build
run: dotnet build --configuration Release ./backend --runtime linux-x64 # Build the project

- name: Deploy to server
run: |
cp -rf ./backend/bin/net8.0/linux-x64/* /home/datnt/datj-backend/
shell: bash
# name: CI/CD Pipeline

# on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main

# jobs:
# build-and-deploy:
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v2

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1

# - name: Log in to Azure Container Registry
# uses: azure/docker-login@v1
# with:
# login-server: <YourACRName>.azurecr.io
# username: ${{ secrets.AZURE_ACR_USERNAME }}
# password: ${{ secrets.AZURE_ACR_PASSWORD }}

# - name: Build and push backend Docker image
# run: |
# docker-compose -f docker-compose.yml build backend
# docker tag myapp_backend:latest <YourACRName>.azurecr.io/myapp_backend:latest
# docker push <YourACRName>.azurecr.io/myapp_backend:latest

# - name: Build and push frontend Docker image
# run: |
# docker-compose -f docker-compose.yml build frontend
# docker tag myapp_frontend:latest <YourACRName>.azurecr.io/myapp_frontend:latest
# docker push <YourACRName>.azurecr.io/myapp_frontend:latest

# - name: Deploy to Azure Web App
# uses: azure/webapps-deploy@v2
# with:
# app-name: <YourAppServiceName>
# slot-name: production
# images: |
# <YourACRName>.azurecr.io/myapp_backend:latest
# <YourACRName>.azurecr.io/myapp_frontend:latest
2 changes: 1 addition & 1 deletion backend/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ApplicationDbContext() { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
"Server=tcp:datj.database.windows.net,1433;Initial Catalog=DATJ;Persist Security Info=False;User ID=germanypeach;Password=GerPeach@123;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
"Server=tcp:datj.database.windows.net,1433;Initial Catalog=DATJ1;Persist Security Info=False;User ID=germanypeach;Password=GerPeach@123;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
options => options.CommandTimeout(180)
); // Timeout in seconds
}
Expand Down
23 changes: 12 additions & 11 deletions backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public static void Main(string[] args)
.ReferenceLoopHandling
.Ignore;
});



// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand Down Expand Up @@ -135,7 +136,7 @@ public static void Main(string[] args)
)
};
});

builder.Services.AddScoped<ITransactionRepository, TransactionRepository>();
builder.Services.AddScoped<IWarrantyRequestRepository, WarrantyRequestRepository>();
builder.Services.AddScoped<IShapeRepository, ShapeRepository>();
Expand Down Expand Up @@ -176,16 +177,16 @@ public static void Main(string[] args)
}

app.UseHttpsRedirection();

app.UseCors(x =>
x.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.WithOrigins("https://datj.id.vn")
.SetIsOriginAllowed(origin => true)
);



app.UseRouting();
app.UseCors(options =>
{
options.AllowAnyOrigin();
options.AllowAnyHeader();
options.AllowAnyMethod();
}
);

app.UseAuthentication();
app.UseAuthorization();
Expand Down
2 changes: 1 addition & 1 deletion backend/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=tcp:datj.database.windows.net,1433;Initial Catalog=DATJ;Persist Security Info=False;User ID=germanypeach;Password=GerPeach@123;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
"DefaultConnection": "Server=tcp:datj.database.windows.net,1433;Initial Catalog=DATJ1;Persist Security Info=False;User ID=germanypeach;Password=GerPeach@123;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},
"Logging": {
"LogLevel": {
Expand Down
23 changes: 12 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
version: "3.9"

services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- frontend
- backend

backend:
build:
context: ./backend
Expand All @@ -20,19 +30,10 @@ services:
depends_on:
- backend
environment:
- REACT_APP_API_URL=http://localhost:8080
- VITE_SERVER_URL=http://localhost:8080
- REACT_APP_API_URL=http://localhost
- VITE_SERVER_URL=http://localhost
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
volumes:
- ./frontend/src:/app/src
- /app/node_modules

# db:
# image: mcr.microsoft.com/mssql/server:2019-latest
# container_name: sql-server-container
# environment:
# - ACCEPT_EULA=Y
# - SA_PASSWORD=GerPeach@123
# ports:
# - "1433:1433"
9 changes: 3 additions & 6 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ COPY package.json package-lock.json ./
# Install dependencies
RUN npm install

# Copy the rest of the application code
# Copy the rest of the application code including src folder
COPY . .

# Build the application
RUN npm run build

# FROM nginx:alpine
# COPY --from=builder /app/dist /usr/share/nginx/html
# Expose the port the app runs on
EXPOSE 3000

# Start Nginx server
# CMD ["nginx", "-g", "daemon off;"]
CMD [ "npm", "run","dev" ]
# Start the application
CMD ["npm", "run", "dev"]
2 changes: 1 addition & 1 deletion frontend/src/pages/dashboard/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gem, HandCoins, Sparkles, TicketPercent, Wrench } from "lucide-react";
import { Gem, HandCoins, Sparkles, TicketPercent } from "lucide-react";
import { Link, useLocation, useNavigate } from "react-router-dom";
import classNames from "classnames";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const TransactionChart: React.FC = () => {
setFormattedData(formattedData);
})();
}, [firstMonth, lastMonth]);
console.log(data);
useEffect(() => {
const months = getLast12Months();
setFirstMonth(months[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState } from "react";
import { Statistic, Typography } from "antd";
const { Countdown } = Statistic;
const { Text } = Typography;
Expand All @@ -12,7 +11,6 @@ export const CountdownComponent = ({ startTime, endTime }: any) => {
const onFinish = () => {
console.log("Countdown finished");
};
console.log("isExpired", isExpired);
let content;
if (now < startTimestamp) {
content = (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/dashboard/warranty_card/CardManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import { Form, Input, Pagination, Empty } from "antd";
import { useSearchStore } from "../../../store/searchStore";
import { GET } from "../../../utils/request";
Expand All @@ -9,7 +9,7 @@ import LoadingItem from "./components/LoadingItem";
import CardRow from "./components/CardRow";

export default function CardManagement() {
const location = useLocation();
// const location = useLocation();

// sort item
const columnHeaders = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQueries } from "@tanstack/react-query";
import { GET } from "../../../../utils/request";
// import { useQueries } from "@tanstack/react-query";
// import { GET } from "../../../../utils/request";

export default function WarrantyRow({ card }: { card: any }) {
return (
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Explore from "./components/Explore";
import Diamond from "./components/Diamond";
import Content from "./components/Content";
import { Carousel } from "antd";
import Banner1 from "./components/banner/Banner1";
import Banner2 from "./components/banner/Banner2";
// import Banner1 from "./components/banner/Banner1";
// import Banner2 from "./components/banner/Banner2";
import Banner3 from "./components/banner/Banner3";
import Banner4 from "./components/banner/Banner4";
// import Banner4 from "./components/banner/Banner4";
// import Banner5 from "./components/banner/Banner5";
import Banner7 from "./components/banner/Banner7";
// import Banner7 from "./components/banner/Banner7";
export default function Home() {
return (
<div className="">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/home/components/Explore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Carousel } from "antd";
import { featuredProduct } from "./featuredProduct";
import { useState, useEffect } from "react";
// import { useState, useEffect } from "react";

const ProductItem = ({ url, title }: { url: string; title: string }) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/product/diamond/DiamondDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEffect, useState } from "react";
export default function DiamondDetail() {
const { diamondId } = useParams();
const [loadingCertificate, setLoadingCertificate] = useState(false);
const [certificate, setCertificate] = useState("");
// const [certificate, setCertificate] = useState("");

const [diamond, diamondPrice, priceRate] = useQueries({
queries: [
Expand Down
19 changes: 19 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;

location / {
proxy_pass http://frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /api {
proxy_pass http://backend:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

0 comments on commit 90afdf7

Please sign in to comment.