| -rw-r--r-- | .github/workflows/build-and-deploy.yml | 38 | ||||
| -rw-r--r-- | deploy/inventory.yml | 28 | ||||
| -rw-r--r-- | deploy/playbook.yml | 13 |
3 files changed, 48 insertions, 31 deletions
diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 57cfc96..ffb81c5 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -8,6 +8,8 @@ jobs: if: github.repository == 'SayaAndy/saya-today-web' runs-on: ubuntu-latest environment: Production + permissions: + packages: write steps: - name: Checkout uses: actions/checkout@v4 @@ -18,17 +20,17 @@ jobs: output: static/output.css params: "--minify" - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GHCR_TOKEN }} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile @@ -45,22 +47,36 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up SSH private key + + - name: Set up SSH connection for pl.saya.today + run: | + mkdir -p ~/.ssh + (cat <<EOF + ${{ secrets.SVC_GITHUB_PK }} + EOF + ) > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + sed -i 's/\r$//' ~/.ssh/id_ed25519 + ssh-keyscan -H pl.saya.today >> ~/.ssh/known_hosts + + - name: Test SSH connection run: | - echo "${{ secrets.SVC_GITHUB_PK }}" > deploy/private_key.pem - chmod 600 deploy/private_key.pem + ssh -o ConnectTimeout=10 -i ~/.ssh/id_rsa svc_github@pl.saya.today "echo 'SSH connection successful'" + - name: Install Ansible shell: bash run: | sudo apt update sudo apt install -y ansible + - name: Run Ansible playbook env: ANSIBLE_HOST_KEY_CHECKING: False working-directory: ./deploy run: > ansible-playbook -i inventory.yml -l stage playbook.yml - --private-key private_key.pem - -e saya_today_web.b2.key_id=${{ secrets.B2_KEY_ID }} - -e saya_today_web.b2.application_key=${{ secrets.B2_APPLICATION_KEY }} - -e saya_today_web.tag=${{ github.ref_name }} + --private-key ~/.ssh/id_ed25519 + -u svc_github + -e saya_today_web_b2_key_id=${{ secrets.B2_KEY_ID }} + -e saya_today_web_b2_application_key=${{ secrets.B2_APPLICATION_KEY }} + -e saya_today_web_tag=${{ github.ref_name }} diff --git a/deploy/inventory.yml b/deploy/inventory.yml index d3c325f..3c1220d 100644 --- a/deploy/inventory.yml +++ b/deploy/inventory.yml @@ -1,15 +1,15 @@ -prod: - hosts: - pl.saya.today: - saya_today_web: - name: sayana-web - hostname: sayana-web - ipv4_address: 172.16.0.18 +all: + children: + prod: + hosts: + pl.saya.today: + saya_today_web_name: sayana-web + saya_today_web_hostname: sayana-web + saya_today_web_ipv4_address: 172.16.0.18 -stage: - hosts: - pl.saya.today: - saya_today_web: - name: sayana-demo - hostname: sayana-demo - ipv4_address: 172.16.0.17 + stage: + hosts: + pl.saya.today: + saya_today_web_name: sayana-demo + saya_today_web_hostname: sayana-demo + saya_today_web_ipv4_address: 172.16.0.17 diff --git a/deploy/playbook.yml b/deploy/playbook.yml index 571ed2b..caeb8ef 100644 --- a/deploy/playbook.yml +++ b/deploy/playbook.yml @@ -1,20 +1,21 @@ --- - name: Deploy saya-today-web Docker Container + hosts: all remote_user: svc_github tasks: - name: Deploy saya-today-web Docker Container community.docker.docker_container: - name: "{{ saya_today_web.name }}" - hostname: "{{ saya_today_web.hostname }}" - image: "ghcr.io/sayaandy/saya-today-web:{{ saya_today_web.tag }}" + name: "{{ saya_today_web_name }}" + hostname: "{{ saya_today_web_hostname }}" + image: "ghcr.io/sayaandy/saya-today-web:{{ saya_today_web_tag }}" env: - B2_KEY_ID: "{{ saya_today_web.b2.key_id }}" - B2_APPLICATION_KEY: "{{ saya_today_web.b2.application_key }}" + B2_KEY_ID: "{{ saya_today_web_b2_key_id }}" + B2_APPLICATION_KEY: "{{ saya_today_web_b2_application_key }}" network_mode: caddy networks: - name: caddy - ipv4_address: "{{ saya_today_web.ipv4_address }}" + ipv4_address: "{{ saya_today_web_ipv4_address }}" restart_policy: unless-stopped no_log: true ... |