diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5df6f20 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.DS_Store +node_modules +.env +*storybook.log +.next + + +localhost+1-key.pem +localhost+1.pem +*.pem + +my.secrets \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..57d4a01 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,78 @@ +name: frontend deploy +on: + push: + branches: + - feat/36 + +jobs: + docker_image_push: + name: Push to container registry + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to NCP Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.CONTAINER_REGISTRY_URL }} + username: ${{ secrets.NCP_ACCESS_KEY }} + password: ${{ secrets.NCP_SECRET_KEY }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.CONTAINER_REGISTRY_URL }}/nextjs-server:latest + cache-from: type=registry,ref=${{ secrets.CONTAINER_REGISTRY_URL }}/prv-frontend:latest + cache-to: type=inline + secrets: | + GIT_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} + + docker_image_pull: + name: Connect server ssh and pull from container registry + needs: docker_image_push + runs-on: ubuntu-latest + steps: + - name: Get Github Actions IP + id: ip + uses: haythem/public-ip@v1.2 + + - name: Setting NCP CLI & Credentials + run: | + cd ~ + wget https://www.ncloud.com/api/support/download/5/65 + unzip 65 + mkdir ~/.ncloud + echo -e "[DEFAULT]\nncloud_access_key_id = ${{ secrets.NCP_ACCESS_KEY }}\nncloud_secret_access_key = ${{ secrets.NCP_SECRET_KEY }}\nncloud_api_url = ${{ secrets.NCP_API_URL }}" >> ~/.ncloud/configure + + - name: Add Github Action Ip to Security group + run: | + chmod -R 777 ~/cli_linux + cd ~/cli_linux + ./ncloud vserver addAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NCP_VPC_ID }} --accessControlGroupNo ${{ secrets.NCP_AGC_ID }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ steps.ip.outputs.ipv4 }}/32', portRange='${{ secrets.SSH_PORT }}'" + + - name: Connect SSH + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.NCP_SERVER_HOST }} + username: ${{ secrets.NCP_SERVER_USERNAME }} + password: ${{ secrets.NCP_SERVER_PASSWORD }} + port: ${{ secrets.NCP_SERVER_PORT }} + script: | + docker pull ${{ secrets.CONTAINER_REGISTRY_URL }}/nextjs-server + docker stop $(docker ps -a -q) + docker rm $(docker ps -a -q) + docker compose up -d + docker image prune -f + + - name: Remove Github Action Ip to Security group + run: | + chmod -R 777 ~/cli_linux + cd ~/cli_linux + ./ncloud vserver removeAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NCP_VPC_ID }} --accessControlGroupNo ${{ secrets.NCP_AGC_ID }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ steps.ip.outputs.ipv4 }}/32', portRange='${{ secrets.SSH_PORT }}'" diff --git a/.gitignore b/.gitignore index f827e02..88b4944 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ node_modules localhost+1-key.pem localhost+1.pem -*.pem \ No newline at end of file +*.pem + +my.secrets \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..28bff21 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM node:20 + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +CMD ["npm", "run", "dev"]