Build Docker image, push it and deploy #202
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: Build Docker image, push it and deploy | |
| run-name: Build Docker image, push it and deploy | |
| permissions: | |
| contents: read | |
| packages: write | |
| pull-requests: write | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - 'main' | |
| schedule: | |
| # Build the image regularly (each Friday) | |
| - cron: '13 23 * * 5' | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: "etf2l/${{ github.event.repository.name }}" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Cleanup build folder | |
| run: | | |
| ls -la ./ | |
| rm -rf ./* || true | |
| rm -rf ./.??* || true | |
| ls -la ./ | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.GH_LOGIN }} | |
| password: ${{ secrets.GH_ACCESS }} | |
| - name: Docker meta | |
| id: docker_meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Build and push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
| labels: ${{ steps.docker_meta.outputs.labels }} | |
| deploy: | |
| runs-on: [self-hosted, linux, x64] | |
| needs: [build] | |
| steps: | |
| - name: Deploy to ETF2L | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.ETF2L_HOST }} | |
| username: ${{ secrets.ETF2L_USER }} | |
| key: ${{ secrets.ETF2L_KEY }} | |
| port: ${{ secrets.ETF2L_PORT }} | |
| script: | | |
| echo "Log into the ghcr.io registry" | |
| echo ${{ secrets.GH_ACCESS }} | docker login ghcr.io -u ${{ secrets.GH_LOGIN }} --password-stdin | |
| echo "Pull and restart the container" | |
| docker compose -f /home/${{ secrets.ETF2L_USER }}/docker/rules/docker-compose.yml up -d |