fix: version actions/checkout #3
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: CI/CD Bennu Code | |
| on: | |
| push: | |
| branches: | |
| - feat/ci-cd | |
| env: | |
| GIT_USERNAME: ${{ github.actor }} | |
| GIT_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
| IMAGE_TAG: latest | |
| DOCKERFILE: ${{ secrets.DOCKERFILE || './Dockerfile' }} | |
| IMAGE_NAME: ghcr.io/${{ github.repository }} | |
| IMAGE_REGISTRY_URL: ${{ secrets.IMAGE_REGISTRY_URL || 'https://ghcr.io' }} | |
| IMAGE_REGISTRY_USER: ${{ secrets.IMAGE_REGISTRY_USER || github.actor }} | |
| IMAGE_REGISTRY_PASSWORD: ${{ secrets.IMAGE_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }} | |
| jobs: | |
| build-and-push: | |
| name: Build & Push Docker Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout código | |
| uses: actions/checkout@v4.2.2 | |
| - name: Login a GHCR | |
| uses: docker/login-action@v3.4.0 | |
| with: | |
| registry: ${{ env.IMAGE_REGISTRY_URL }} | |
| username: ${{ env.IMAGE_REGISTRY_USER }} | |
| password: ${{ env.IMAGE_REGISTRY_PASSWORD }} | |
| - name: Build & Push imagen | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ${{ env.DOCKERFILE }} | |
| push: true | |
| tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
| deploy: | |
| name: Deploy en EC2 | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| steps: | |
| - name: Deploy via SSH | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin | |
| docker pull ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
| docker stop bennu-code || true | |
| docker rm bennu-code || true | |
| docker run -d \ | |
| --name bennu-code \ | |
| --restart always \ | |
| -p 3000:3000 \ | |
| ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} |