From 5c09677d147271ffe5b61c81e941cf36e30cee58 Mon Sep 17 00:00:00 2001 From: 2paperstar Date: Thu, 6 Jun 2024 03:20:22 +0900 Subject: [PATCH] chore: make dockerfile --- .github/workflows/staging.yaml | 78 ++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++++ src/pages/MainPage.tsx | 3 +- 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/staging.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml new file mode 100644 index 0000000..53261d7 --- /dev/null +++ b/.github/workflows/staging.yaml @@ -0,0 +1,78 @@ +name: Update Kubernetes Cluster (Dev) + +on: + push: + branches: + - main + +jobs: + build: + name: Build docker Image + runs-on: ubuntu-latest + outputs: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: check-out-frontend + IMAGE_TAG: dev${{ github.run_number }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + mask-aws-account-id: no + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build, tag, and push image to Amazon ECR + uses: docker/build-push-action@v2 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: check-out-frontend + IMAGE_TAG: dev${{ github.run_number }} + with: + platforms: linux/arm64 + context: . + push: true + tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy: + name: Update Git Repository + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + repository: Hot-Spicy-Buffalo-Wing/check-out-gitops + ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} + fetch-depth: 0 + + - name: Update Kubernetes Manifest + env: + ECR_REGISTRY: ${{ needs.build.outputs.ECR_REGISTRY }} + ECR_REPOSITORY: ${{ needs.build.outputs.ECR_REPOSITORY }} + IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} + run: | + sed -i "s|image:.*frontend.*|image: $ECR_REGISTRY\/$ECR_REPOSITORY:$IMAGE_TAG|g" check-out/values.yaml + + - name: Commit and Push + env: + ECR_REPOSITORY: ${{ needs.build.outputs.ECR_REPOSITORY }} + IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} + run: | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.name "GitHub Actions" + git commit -am "Update image $ECR_REPOSITORY:$IMAGE_TAG" + git push -u origin main diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c88e458 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:20 as build + +WORKDIR /app + +COPY ./package.json ./yarn.lock ./ + +RUN yarn install + +COPY . . + +RUN yarn build + +# production environment + +FROM nginx:1.16.0-alpine + +COPY --from=build /app/dist /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index 7f29aff..7fe5077 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -7,7 +7,6 @@ import { MantineProvider, createTheme, } from '@mantine/core'; -import api from '../api'; import useUser from '../hooks/useUser'; import { updateUser } from '../api/auth'; import { Link } from 'react-router-dom'; @@ -51,7 +50,7 @@ function MainPage() { const [ageRange, setAgeRange] = useState(''); const [error, setError] = useState(''); - const { user, loading } = useUser(); + const { user } = useUser(); useEffect(() => { const fetchUserInfo = async () => {