From ccc23cdc5cc5c8c781b8e4ecffa706d4f9034e7b Mon Sep 17 00:00:00 2001 From: Dean Lofts Date: Fri, 2 Aug 2024 20:05:04 +1000 Subject: [PATCH] lets try --- .github/workflows/deploy.yml | 43 ++++++++++++++++++++++++++++++++++++ terraform/main.tf | 13 ++++++----- 2 files changed, 51 insertions(+), 5 deletions(-) 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..601d78c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,43 @@ +name: Deploy + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + +jobs: + deploy: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GH_PAT }} + + - name: Build and push Docker image + run: | + echo "${{ secrets.GH_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + GITHUB_TOKEN=${{ secrets.GH_PAT }} docker buildx build --secret id=GITHUB_TOKEN -t ghcr.io/loftwah/linkarooie:latest --push . + + - name: Deploy to droplet + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DROPLET_IP }} + username: root + key: ${{ secrets.DROPLET_SSH_PRIVATE_KEY }} + script: | + echo "${{ secrets.GH_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + docker compose -f /root/docker-compose.prod.yml --env-file /root/.env down + docker compose -f /root/docker-compose.prod.yml --env-file /root/.env pull + docker compose -f /root/docker-compose.prod.yml --env-file /root/.env up -d diff --git a/terraform/main.tf b/terraform/main.tf index b853b1c..0f56e46 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -5,9 +5,12 @@ resource "digitalocean_droplet" "web" { image = "ubuntu-22-04-x64" ssh_keys = [var.ssh_key_id] user_data = <<-EOF - #!/bin/bash - # Install Docker - curl -fsSL https://get.docker.com -o get-docker.sh - sh get-docker.sh - EOF + #!/bin/bash + # Update package list + apt-get update + + # Install Docker using get.docker.com script + curl -fsSL https://get.docker.com -o get-docker.sh + sh get-docker.sh + EOF } \ No newline at end of file