2024-10-17 17:24:42 +00:00
|
|
|
name: Debian images
|
2023-05-12 00:59:36 +00:00
|
|
|
|
|
|
|
on:
|
2023-05-12 01:32:46 +00:00
|
|
|
workflow_dispatch:
|
2023-05-12 01:04:17 +00:00
|
|
|
push:
|
|
|
|
paths:
|
2023-05-12 08:11:38 +00:00
|
|
|
- 'tools/qemu-debian-img/**'
|
2023-05-12 09:12:18 +00:00
|
|
|
- '.github/workflows/images-debian.yml'
|
2023-05-12 00:59:36 +00:00
|
|
|
|
2023-05-18 11:58:53 +00:00
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow_ref }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
2023-05-12 00:59:36 +00:00
|
|
|
jobs:
|
2023-05-12 06:58:17 +00:00
|
|
|
images:
|
2023-05-17 10:24:28 +00:00
|
|
|
name: Qemu Images
|
2023-05-12 00:59:36 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-05-12 06:58:17 +00:00
|
|
|
- uses: digitalocean/action-doctl@v2
|
2023-05-12 01:31:14 +00:00
|
|
|
with:
|
2023-05-12 06:58:17 +00:00
|
|
|
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
|
2023-05-12 01:31:14 +00:00
|
|
|
|
2023-05-12 06:58:17 +00:00
|
|
|
- uses: webfactory/ssh-agent@v0.8.0
|
2023-05-12 01:31:14 +00:00
|
|
|
with:
|
2023-05-12 06:58:17 +00:00
|
|
|
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
2023-05-12 01:31:14 +00:00
|
|
|
|
2023-05-12 06:58:17 +00:00
|
|
|
- name: create droplet
|
2023-05-12 08:11:38 +00:00
|
|
|
run: doctl compute droplet create --ssh-keys='b4:4c:66:7d:be:19:25:43:1c:e0:02:61:9f:49:12:94' --tag-name=github-actions ga-out-of-tree-images-debian-$GITHUB_SHA --size s-1vcpu-1gb --image ubuntu-22-04-x64 --wait
|
2023-05-12 01:31:14 +00:00
|
|
|
|
2023-05-12 12:12:41 +00:00
|
|
|
# TODO Move to common script
|
2023-05-12 06:58:17 +00:00
|
|
|
- name: generate images
|
2023-05-12 10:56:22 +00:00
|
|
|
shell: bash
|
2023-05-12 06:58:17 +00:00
|
|
|
run: |
|
2023-05-12 12:35:55 +00:00
|
|
|
sleep 1m
|
|
|
|
|
2023-05-12 08:11:38 +00:00
|
|
|
IP=$(doctl compute droplet list --tag-name=github-actions --format "Name,Public IPv4" | grep -v ID | grep ga-out-of-tree-images-debian-$GITHUB_SHA | awk '{print $2}')
|
2023-05-12 10:56:22 +00:00
|
|
|
|
2023-05-12 11:07:39 +00:00
|
|
|
while ! ssh -o StrictHostKeyChecking=accept-new root@$IP echo
|
2023-05-12 10:56:22 +00:00
|
|
|
do
|
|
|
|
sleep 1s
|
|
|
|
done
|
|
|
|
|
2023-05-12 12:29:01 +00:00
|
|
|
sleep 5m
|
2023-05-12 12:12:41 +00:00
|
|
|
ssh root@$IP pkill apt-get || true
|
2023-05-12 11:00:07 +00:00
|
|
|
|
2023-05-12 07:47:22 +00:00
|
|
|
ssh root@$IP apt-get update
|
|
|
|
ssh root@$IP apt-get install -y git podman s3cmd
|
|
|
|
ssh root@$IP git clone https://github.com/out-of-tree/out-of-tree
|
|
|
|
ssh root@$IP "cd out-of-tree && git checkout $GITHUB_SHA"
|
2023-05-12 10:56:22 +00:00
|
|
|
|
2023-05-12 12:07:42 +00:00
|
|
|
ssh root@$IP "echo -e '[Unit]\nDescription=Debian image generator and uploader\n[Service]\nRemainAfterExit=yes\nStandardError=append:/var/log/images-debian.log\nStandardOutput=append:/var/log/images-debian.log\nType=oneshot' >> /etc/systemd/system/images-debian.service"
|
2023-05-12 10:56:22 +00:00
|
|
|
|
|
|
|
ssh root@$IP "echo Environment=HOST=fra1.digitaloceanspaces.com >> /etc/systemd/system/images-debian.service"
|
|
|
|
ssh root@$IP "echo Environment=HOST_BUCKET=out-of-tree.fra1.digitaloceanspaces.com >> /etc/systemd/system/images-debian.service"
|
|
|
|
ssh root@$IP "echo Environment=ACCESS_KEY=${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }} >> /etc/systemd/system/images-debian.service"
|
|
|
|
ssh root@$IP "echo Environment=SECRET_KEY=${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }} >> /etc/systemd/system/images-debian.service"
|
|
|
|
|
|
|
|
ssh root@$IP "echo 'ExecStart=/root/out-of-tree/tools/qemu-debian-img/generate-images.sh' >> /etc/systemd/system/images-debian.service"
|
|
|
|
|
|
|
|
ssh root@$IP 'echo ExecStart=/bin/sh -c \"s3cmd put --acl-public /root/out-of-tree/tools/qemu-debian-img/*.tar.gz s3://out-of-tree/1.0.0/ --host=\$HOST --host-bucket=\$HOST_BUCKET --access_key=\$ACCESS_KEY --secret_key=\$SECRET_KEY\" >> /etc/systemd/system/images-debian.service'
|
|
|
|
|
|
|
|
ssh root@$IP "echo TimeoutStopSec=1 >> /etc/systemd/system/images-debian.service"
|
|
|
|
|
|
|
|
ssh root@$IP systemctl daemon-reload
|
|
|
|
|
|
|
|
ssh root@$IP systemctl start images-debian --no-block
|
|
|
|
|
2023-05-12 12:07:42 +00:00
|
|
|
while ! ssh root@$IP systemctl show images-debian -p SubState --value | grep -E '(failed|exited)'
|
|
|
|
do
|
2023-05-12 12:16:32 +00:00
|
|
|
sleep 3m
|
2023-05-12 10:56:22 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
scp root@$IP:/var/log/images-debian.log .
|
|
|
|
|
2023-05-12 12:07:42 +00:00
|
|
|
ssh root@$IP systemctl is-active images-debian
|
|
|
|
|
2023-05-12 10:56:22 +00:00
|
|
|
- name: Archive logs
|
|
|
|
if: always()
|
2024-02-20 15:09:58 +00:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-05-12 10:56:22 +00:00
|
|
|
with:
|
|
|
|
name: images-debian-log
|
|
|
|
path: images-debian.log
|
2023-05-12 06:58:17 +00:00
|
|
|
|
2023-05-12 07:47:22 +00:00
|
|
|
- name: delete droplet
|
|
|
|
if: always()
|
2023-05-12 08:11:38 +00:00
|
|
|
run: doctl compute droplet delete -f ga-out-of-tree-images-debian-$GITHUB_SHA
|