hotfix: pull main #50
This file contains hidden or 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: CD Pipeline | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| cd: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| install: true | |
| - name: Create buildx builder | |
| run: | | |
| docker buildx create --use --name mybuilder | |
| docker buildx inspect --bootstrap | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build & Push Dependency Cache | |
| run: | | |
| docker buildx build \ | |
| --builder mybuilder \ | |
| --platform linux/amd64 \ | |
| --push \ | |
| --file Dockerfile \ | |
| --tag ${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache \ | |
| --target dependencies \ | |
| --cache-to type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache,mode=max \ | |
| . | |
| - name: Build & Push Final App Image (Production) | |
| run: | | |
| docker buildx build \ | |
| --builder mybuilder \ | |
| --platform linux/amd64 \ | |
| --push \ | |
| --file Dockerfile \ | |
| --tag ${{ secrets.DOCKERHUB_USERNAME }}/haru-app:latest \ | |
| --build-arg DEPENDENCY_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache \ | |
| --cache-from type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache \ | |
| . | |
| - name: Create application-secret.yml | |
| run: | | |
| mkdir -p ./temp_secret | |
| echo "${{ secrets.APPLICATION_SECRET }}" > ./temp_secret/application-secret.yml | |
| shell: bash | |
| - name: Copy application-secret.yml to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| username: ubuntu | |
| host: ${{ secrets.EC2_HOST }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: ./temp_secret/application-secret.yml | |
| target: /home/ubuntu/secret/ | |
| - name: Copy docker-compose.yml | |
| uses: appleboy/[email protected] | |
| with: | |
| username: ubuntu | |
| host: ${{ secrets.EC2_HOST }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: ./docker-compose.yml | |
| target: /home/ubuntu/cicd/spring/ | |
| - name: Upload deploy.sh to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: ./deploy.sh | |
| target: /home/ubuntu/cicd/spring | |
| - name: SSH and Deploy | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/haru-app:latest | |
| sudo chmod +x /home/ubuntu/cicd/spring/deploy.sh | |
| sudo /home/ubuntu/cicd/spring/deploy.sh |