diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0365186..14a4316 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,12 +5,67 @@ on: branches: ["main"] pull_request: branches: ["main"] + schedule: + - cron: "0 0 * * 0" jobs: - build-container: + build-push-deploy: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - - name: Build container - run: docker build -t hello-icerpc . + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64 + tags: | + icerpc/hello:latest + ghcr.io/icerpc/hello:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Deploy + uses: appleboy/ssh-action@v1.0.3 + if: github.event_name != 'pull_request' + with: + host: ${{ secrets.HELLO_HOST }} + username: ${{ secrets.HELLO_USERNAME }} + key: ${{ secrets.SSH_DEPLOY_KEY }} + script_stop: true + script: | + cd /opt/hello + docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} + docker compose pull hello-icerpc + docker compose up -d hello-icerpc + docker system prune -f + + - name: Delete old container images + uses: actions/delete-package-versions@v5 + with: + package-name: hello + package-type: container + min-versions-to-keep: 10 + delete-only-untagged-versions: true