diff --git a/.github/workflows/stage-cd.yml b/.github/workflows/stage-cd.yml new file mode 100644 index 00000000..8e51bc8f --- /dev/null +++ b/.github/workflows/stage-cd.yml @@ -0,0 +1,58 @@ +name: CD for Stage + +on: + push: + branches: + - main + +jobs: + build: + environment: stage + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'zulu' + + - name: Build Gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: | + build + --build-cache + --no-daemon + + - name: Login to ECR + id: ecr + uses: elgohr/ecr-login-action@master + with: + access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} + secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + region: ${{ secrets.AWS_REGION }} + + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: ${{ secrets.ECR_REPOSITORY }} + username: ${{ steps.ecr.outputs.username }} + password: ${{ steps.ecr.outputs.password }} + registry: ${{ steps.ecr.outputs.registry }} + + - name: Connect EC2 & Deploy Docker Image + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + port: ${{ secrets.EC2_PORT }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_KEY }} + script: | + cd simtong-server + aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.DOCKER_IMAGE }} + docker pull ${{ secrets.DOCKER_IMAGE }} + docker rm -f simtong-server || true + docker run -d --name simtong-server -p ${{ secrets.APPLICATION_PORT }}:8080 --env-file .env ${{ secrets.DOCKER_IMAGE }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e227e631 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM eclipse-temurin:17-jre-focal + +EXPOSE 8080 +ENV TZ=Asia/Seoul + +COPY ./simtong-infrastructure/build/libs/*.jar app.jar +ENTRYPOINT ["java","-jar","-Dspring.profiles.active=prod","/app.jar"] \ No newline at end of file