From e1c3c31599a5e26f0dca7d6f65fae6cc3738a474 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 9 Jul 2024 17:10:03 -0600 Subject: [PATCH] actions: Add initial deploy workflow --- .github/workflows/deploy.yml | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..59a5cdc --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,67 @@ +name: Deploy to DigitalOcean + +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - id: setup_buildx + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + builder: ${{ steps.setup_buildx.outputs.name }} + cache-from: type=gha + cache-to: type=gha, mode=max + tags: lyraphase/phasik.tv:latest,lyraphase/phasik.tv:${{ github.sha }} + # tags: registry.digitalocean.com//:${{ github.sha }} + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Set app ID variable + id: app_id + run: echo "APP_ID=$(doctl apps list --no-header --format 'ID,Spec.Name' | grep 'docker-phasik-tv' | awk '{print $1}')" >> $GITHUB_ENV + + - name: Deploy to DigitalOcean App + run: doctl apps update ${{ steps.app_id.outputs.APP_ID }} --spec ${{github.workspace}}/.do/app.yaml + + # - name: Deploy to DigitalOcean App (no spec update) + # run: doctl apps create-deployment ${{ steps.app_id.outputs.APP_ID }} --wait + # TODO: Use DigitalOcean K8s for scaling? + # - name: Log in to DigitalOcean Container Registry + # run: doctl registry login + + # - name: Update deployment file + # run: | + # TAG=${{ github.sha }} + # sed -i 's||registry.digitalocean.com//:'${TAG}'|' k8s/deployment.yml + + # - name: Save DigitalOcean kubeconfig + # run: doctl kubernetes cluster kubeconfig save + + # - name: Deploy to DigitalOcean Kubernetes + # run: kubectl apply -f k8s/deployment.yml + + # - name: Verify deployment + # run: kubectl rollout status deployment/