Skip to content

Commit

Permalink
Merge pull request #5 from 100-hours-a-week/feature/elle
Browse files Browse the repository at this point in the history
Feature/elle - Chore : 개발환경 셋팅
  • Loading branch information
Yeonsu00-12 authored Aug 14, 2024
2 parents 7a33034 + 96bdea3 commit 052ebb8
Show file tree
Hide file tree
Showing 55 changed files with 832 additions and 59 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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: Build Docker Image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/ustock-frontend:${{ github.sha }} .
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push Docker Image
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/ustock-frontend:${{ github.sha }}
deploy-to-ec2:
runs-on: ubuntu-latest
needs: build-and-push

steps:
- name: Get Public IP
id: ip
uses: haythem/[email protected]

- name: Allow SSH access from GitHub Actions
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}

- 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
- name: Revoke SSH access from GitHub Actions
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
3 changes: 3 additions & 0 deletions hth/.gitignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# IntelliJ
.idea

# dependencies
/node_modules
/.pnp
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:14 AS build

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm install

COPY . .

RUN npm run build

FROM nginx:1.21.4-alpine

RUN rm /etc/nginx/conf.d/default.conf

COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
46 changes: 0 additions & 46 deletions hth/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions hth/src/App.test.tsx

This file was deleted.

1 change: 0 additions & 1 deletion hth/src/logo.svg

This file was deleted.

46 changes: 46 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
keepalive_timeout 65;

# Gzip settings
gzip on;
gzip_types text/plain application/xml application/json application/javascript text/css;

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;
}
}
}
Loading

0 comments on commit 052ebb8

Please sign in to comment.