Merge pull request #117 from Devminjeong-eum/chore/DEV-37 #139
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Devminjeong-eum-FrontEnd-Production | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Environment Variable Setting | |
run: | | |
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" >> .env | |
echo "KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}" >> .env | |
echo "KAKAO_SECRET_KEY=${{ secrets.KAKAO_SECRET_KEY }}" >> .env | |
echo "NEXT_PUBLIC_BACKEND_BASE_URL=${{ secrets.NEXT_PUBLIC_BACKEND_BASE_URL }}" >> .env | |
echo "NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL }}" >> .env | |
echo "NEXT_PUBLIC_KAKAO_SHARE_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_SHARE_KEY }}" >> .env | |
echo "NEXT_PUBLIC_KAKAO_SHARE_TEMPLATE_ID=${{ secrets.NEXT_PUBLIC_KAKAO_SHARE_TEMPLATE_ID }}" >> .env | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and Push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/devminjeong-eum-frontend:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
deploy: | |
needs: docker-image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to AWS EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_SSH_HOST }} | |
username: ${{ secrets.EC2_SSH_USER }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script: | | |
cd /home/${{ secrets.EC2_SSH_USER }}/dev-malssami/frontend | |
sudo docker system prune -a --volumes -f | |
if [ "$(sudo docker ps | grep frontend)" ]; then | |
sudo docker stop frontend | |
sudo docker rm frontend | |
fi | |
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" >> .env.production | |
echo "KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}" >> .env.production | |
echo "KAKAO_SECRET_KEY=${{ secrets.KAKAO_SECRET_KEY }}" >> .env.production | |
echo "NEXT_PUBLIC_BACKEND_BASE_URL=${{ secrets.NEXT_PUBLIC_BACKEND_BASE_URL }}" >> .env.production | |
echo "NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL }}" >> .env.production | |
echo "NEXT_PUBLIC_KAKAO_SHARE_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_SHARE_KEY }}" >> .env.production | |
echo "NEXT_PUBLIC_KAKAO_SHARE_TEMPLATE_ID=${{ secrets.NEXT_PUBLIC_KAKAO_SHARE_TEMPLATE_ID }}" >> .env.production | |
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/devminjeong-eum-frontend:latest | |
sudo docker run -p 3000:3000 \ | |
--name frontend \ | |
--env-file ./.env.production \ | |
-d ${{ secrets.DOCKER_HUB_USERNAME }}/devminjeong-eum-frontend:latest |