diff --git a/.github/workflows/backend-build-alpha-image.yml b/.github/workflows/backend-build-alpha-image.yml new file mode 100644 index 000000000..d01d65e93 --- /dev/null +++ b/.github/workflows/backend-build-alpha-image.yml @@ -0,0 +1,60 @@ +name: Build Alpha Image + +on: + push: + branches: [ develop ] + paths: backend/** +permissions: + id-token: write +jobs: + push-image: + defaults: + run: + working-directory: backend + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: check jar file + run: ls -l build/libs + - name: Build Image + run: docker build . + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::791335373803:role/AWSPushImageToECR + aws-region: ap-northeast-2 + + - name: Amazon ECR "Login" Action for GitHub Actions + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2.0.1 + + - name: push ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: zipgo/alpha-backend + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + - name: Docker Login + run: | + aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_LOGIN_PASSWORD }} + - name: CD on EC2 + uses: zip-go/aws-ssm-action@v1.0.0 + with: + instanceName: ${{ secrets.ALPHA_INSTANCE_NAME }} + workingDirectory: ${{ secrets.ALPHA_WORKING_DIRECTORY }} + commands: | + rm .env + echo IMAGE_TAG=${{ github.sha }} > .env + docker compose restart zipgo-backend \ No newline at end of file diff --git a/.github/workflows/frontend-deploy-dev.yml b/.github/workflows/frontend-deploy-dev.yml index 22dd7f7d2..24f07a1b5 100644 --- a/.github/workflows/frontend-deploy-dev.yml +++ b/.github/workflows/frontend-deploy-dev.yml @@ -4,10 +4,12 @@ on: push: branches: - develop + - feat/alpha-env paths: - frontend/** - .github/** - +permissions: + id-token: write jobs: build-dockerfile: defaults: @@ -58,29 +60,21 @@ jobs: context: ./frontend file: ./frontend/Dockerfile.dev push: true - tags: ${{ secrets.FRONTEND_IMAGE_NAME }}:latest + tags: ${{ secrets.FRONTEND_ALPHA_IMAGE_NAME }}:latest platforms: | linux/amd64 linux/arm64 - deploy-to-develop-EC2: - needs: build-dockerfile - runs-on: front-dev-server - - steps: - - name: Deploy to Develop EC2 - run: | - docker stop ${{ secrets.FRONTEND_CONTAINER_NAME }} || true - docker rm ${{ secrets.FRONTEND_CONTAINER_NAME }} || true - docker pull ${{ secrets.FRONTEND_IMAGE_NAME }}:latest - docker run -d -p 3000:3000 --name ${{ secrets.FRONTEND_CONTAINER_NAME }} ${{ secrets.FRONTEND_IMAGE_NAME }}:latest - - - name: Slack Notification - uses: 8398a7/action-slack@v3 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::791335373803:role/SendCommandToEc2FromGithub + aws-region: ${{ secrets.AWS_REGION }} + - name: CD on EC2 + uses: zip-go/aws-ssm-action@v1.0.0 with: - status: ${{ job.status }} - author_name: 프론트엔드 배포 알림 - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - if: always() + instanceName: ${{ secrets.ALPHA_INSTANCE_NAME }} + workingDirectory: ${{ secrets.ALPHA_WORKING_DIRECTORY }} + commands: | + docker compose restart zipgo-frontend + echo "Succeeded: $GITHUB_SHA" > result.txt \ No newline at end of file diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index b6a662d58..52cd8608c 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,9 +4,9 @@ on: push: branches: [ main, develop ] paths: backend/** - pull_request: - branches: [ main, develop ] - paths: backend/** + # pull_request: + # branches: [ main, develop ] + # paths: backend/** jobs: build: diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.yml index 7f6622ef1..53509f90b 100644 --- a/.github/workflows/storybook.yml +++ b/.github/workflows/storybook.yml @@ -4,9 +4,9 @@ on: push: branches: [main, develop] paths: frontend/** - pull_request: - branches: [main, develop] - paths: frontend/** + # pull_request: + # branches: [main, develop] + # paths: frontend/** jobs: storybook-test: diff --git a/backend/.gitignore b/backend/.gitignore index 92d69ffb0..b81b58102 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -7,6 +7,7 @@ build/ **/src/main/resources/static/docs/ src/main/resources/env.properties +env*.properties ### STS ### .apt_generated diff --git a/backend/docker/docker-compose.dev.yml b/backend/docker-compose.dev.yml similarity index 60% rename from backend/docker/docker-compose.dev.yml rename to backend/docker-compose.dev.yml index 3d8473708..38462a15a 100644 --- a/backend/docker/docker-compose.dev.yml +++ b/backend/docker-compose.dev.yml @@ -2,7 +2,7 @@ version: '3' services: mysql: - container_name: zipgo + container_name: zipgo-mysql image: mysql/mysql-server environment: MYSQL_DATABASE: zipgo-mysql @@ -10,9 +10,16 @@ services: MYSQL_ROOT_PASSWORD: root TZ: 'Asia/Seoul' ports: - - 13306:3306 + - "13306:3306" command: - "mysqld" - "--character-set-server=utf8mb4" - "--collation-server=utf8mb4_unicode_ci" - + springboot: + container_name: zipgo-backend + build: . + env_file: "env.dev.properties" + ports: + - "8080:8080" + depends_on: + - mysql diff --git a/frontend/.env.development b/frontend/.env.development index 750405545..cb0050c73 100644 --- a/frontend/.env.development +++ b/frontend/.env.development @@ -1,3 +1,3 @@ FAST_REFRESH=true -BASE_URL=https://dev.api.zipgo.pet +BASE_URL=http://zipgo-backend HOMEPAGE=https://dev.zipgo.pet