From da23655b3285660606462a40eb54bd81e088ae69 Mon Sep 17 00:00:00 2001 From: yu seungbeom Date: Mon, 12 Aug 2024 13:50:21 +0900 Subject: [PATCH] github actions setting v1 --- .github/workflows/cicd.yml | 55 +++++++++++++++++++++ hth/.gitignore => .gitignore | 3 ++ Dockerfile | 21 ++++++++ hth/README.md | 46 ----------------- nginx.conf | 18 +++++++ hth/package-lock.json => package-lock.json | 0 hth/package.json => package.json | 0 {hth/public => public}/favicon.ico | Bin {hth/public => public}/index.html | 0 {hth/public => public}/logo192.png | Bin {hth/public => public}/logo512.png | Bin {hth/public => public}/manifest.json | 0 {hth/public => public}/robots.txt | 0 {hth/src => src}/App.css | 0 {hth/src => src}/App.test.tsx | 0 {hth/src => src}/App.tsx | 0 {hth/src => src}/index.css | 0 {hth/src => src}/index.tsx | 0 {hth/src => src}/logo.svg | 0 {hth/src => src}/react-app-env.d.ts | 0 {hth/src => src}/reportWebVitals.ts | 0 {hth/src => src}/setupTests.ts | 0 hth/tsconfig.json => tsconfig.json | 0 23 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/cicd.yml rename hth/.gitignore => .gitignore (94%) create mode 100644 Dockerfile delete mode 100644 hth/README.md create mode 100644 nginx.conf rename hth/package-lock.json => package-lock.json (100%) rename hth/package.json => package.json (100%) rename {hth/public => public}/favicon.ico (100%) rename {hth/public => public}/index.html (100%) rename {hth/public => public}/logo192.png (100%) rename {hth/public => public}/logo512.png (100%) rename {hth/public => public}/manifest.json (100%) rename {hth/public => public}/robots.txt (100%) rename {hth/src => src}/App.css (100%) rename {hth/src => src}/App.test.tsx (100%) rename {hth/src => src}/App.tsx (100%) rename {hth/src => src}/index.css (100%) rename {hth/src => src}/index.tsx (100%) rename {hth/src => src}/logo.svg (100%) rename {hth/src => src}/react-app-env.d.ts (100%) rename {hth/src => src}/reportWebVitals.ts (100%) rename {hth/src => src}/setupTests.ts (100%) rename hth/tsconfig.json => tsconfig.json (100%) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..e85b93d --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,55 @@ +name: Frontend CI/CD + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push + uses: docker/build-push-action@v6 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/ustock-frontend:${{ github.sha }} + platforms: linux/amd64,linux/arm64 + + deploy-to-ec2: + runs-on: ubuntu-latest + needs: build-and-push + + steps: + - name: Add SSH key + run: | + mkdir -p ~/.ssh + echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + + - name: Deploy to EC2 via SSH + run: | + ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF' + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ustock-frontend:${{ github.sha }} + docker stop ustock-frontend || true + docker rm ustock-frontend || true + docker run -dp 80:80 --network ustock-network --name ustock-frontend ${{ secrets.DOCKERHUB_USERNAME }}/ustock-frontend:${{ github.sha }} + EOF \ No newline at end of file diff --git a/hth/.gitignore b/.gitignore similarity index 94% rename from hth/.gitignore rename to .gitignore index 4d29575..3d5aee1 100644 --- a/hth/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +# IntelliJ +.idea + # dependencies /node_modules /.pnp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ca4449 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:14 AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ + +RUN npm ci + +COPY . . + +RUN npm run build + +FROM nginx:1.21.4-alpine + +RUN rm /etc/nginx/conf.d/default.conf + +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/hth/README.md b/hth/README.md deleted file mode 100644 index b87cb00..0000000 --- a/hth/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..82f3016 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,18 @@ +server { + listen 80; + server_name _; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location /api/ { + proxy_pass http://ustock-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; + } +} diff --git a/hth/package-lock.json b/package-lock.json similarity index 100% rename from hth/package-lock.json rename to package-lock.json diff --git a/hth/package.json b/package.json similarity index 100% rename from hth/package.json rename to package.json diff --git a/hth/public/favicon.ico b/public/favicon.ico similarity index 100% rename from hth/public/favicon.ico rename to public/favicon.ico diff --git a/hth/public/index.html b/public/index.html similarity index 100% rename from hth/public/index.html rename to public/index.html diff --git a/hth/public/logo192.png b/public/logo192.png similarity index 100% rename from hth/public/logo192.png rename to public/logo192.png diff --git a/hth/public/logo512.png b/public/logo512.png similarity index 100% rename from hth/public/logo512.png rename to public/logo512.png diff --git a/hth/public/manifest.json b/public/manifest.json similarity index 100% rename from hth/public/manifest.json rename to public/manifest.json diff --git a/hth/public/robots.txt b/public/robots.txt similarity index 100% rename from hth/public/robots.txt rename to public/robots.txt diff --git a/hth/src/App.css b/src/App.css similarity index 100% rename from hth/src/App.css rename to src/App.css diff --git a/hth/src/App.test.tsx b/src/App.test.tsx similarity index 100% rename from hth/src/App.test.tsx rename to src/App.test.tsx diff --git a/hth/src/App.tsx b/src/App.tsx similarity index 100% rename from hth/src/App.tsx rename to src/App.tsx diff --git a/hth/src/index.css b/src/index.css similarity index 100% rename from hth/src/index.css rename to src/index.css diff --git a/hth/src/index.tsx b/src/index.tsx similarity index 100% rename from hth/src/index.tsx rename to src/index.tsx diff --git a/hth/src/logo.svg b/src/logo.svg similarity index 100% rename from hth/src/logo.svg rename to src/logo.svg diff --git a/hth/src/react-app-env.d.ts b/src/react-app-env.d.ts similarity index 100% rename from hth/src/react-app-env.d.ts rename to src/react-app-env.d.ts diff --git a/hth/src/reportWebVitals.ts b/src/reportWebVitals.ts similarity index 100% rename from hth/src/reportWebVitals.ts rename to src/reportWebVitals.ts diff --git a/hth/src/setupTests.ts b/src/setupTests.ts similarity index 100% rename from hth/src/setupTests.ts rename to src/setupTests.ts diff --git a/hth/tsconfig.json b/tsconfig.json similarity index 100% rename from hth/tsconfig.json rename to tsconfig.json