name: Deploy

on:
  push:
    branches: [ main ]

jobs:

  publish:
    name: Publish
    runs-on: ubuntu-latest
    steps:

    - name: Checkout
      uses: actions/checkout@v2

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1

    - name: Docker Login
      uses: docker/login-action@v1.6.0
      with:
        registry: ghcr.io
        username: $GITHUB_ACTOR
        password: ${{ secrets.CR_PAT }}

    - name: Build and push Docker images
      uses: docker/build-push-action@v2.1.0
      with:
        pull: true
        platforms: linux/amd64
        push: true
        tags: ghcr.io/serverwentdown/datetime.link:latest

  deploy:
    name: Deploy to pricklypear
    runs-on: ubuntu-latest
    needs: publish
    steps:

    - name: Import SSH key
      run: |
        mkdir -p ~/.ssh
        echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
        chmod 600 ~/.ssh/id_ed25519
        echo "[pricklypear.cacti.makerforce.io]:26779 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGd9tL56+YUDQjyGy3iZNGUtjVkvAD442Q6Kt53Zsy8g" >> ~/.ssh/known_hosts

    - name: Re-pull
      run: |
        ssh -p 26779 datetime@pricklypear.cacti.makerforce.io "podman login --username $GITHUB_ACTOR --password ${{ secrets.CR_PAT }} ghcr.io && podman pull ghcr.io/serverwentdown/datetime.link:latest"

    - name: Restart
      run: |
        ssh -p 26779 datetime@pricklypear.cacti.makerforce.io "systemctl restart --user container-datetime.service"


# vim: set et ts=2 sw=2:
