Skip to content

Commit 100858b

Browse files
committed
chore: cleanup instructions for building image
1 parent 44f115d commit 100858b

File tree

4 files changed

+23
-104
lines changed

4 files changed

+23
-104
lines changed

.github/workflows/nix-build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches:
66
- develop
77
- release/*
8-
- da/qemu*
98
pull_request:
109
workflow_dispatch:
1110

.github/workflows/qemu-image-build.yml

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches:
66
- develop
77
- release/*
8-
- da/merging-qemu
98
paths:
109
- '.github/workflows/qemu-image-build.yml'
1110
- 'qemu-arm64-nix.pkr.hcl'
@@ -62,28 +61,20 @@ jobs:
6261
sudo chown runner /dev/kvm
6362
sudo chmod 666 /dev/kvm
6463
65-
# - name: Install dependencies
66-
# run: |
67-
# sudo apt-get update
68-
# sudo apt-get install -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils
69-
# cd && curl -L "https://releases.hashicorp.com/packer/1.7.8/packer_1.7.8_linux_$(dpkg --print-architecture).zip" -o packer.zip && unzip packer.zip && rm -f packer.zip && sudo mv packer /usr/local/bin/
70-
7164
- name: Set PostgreSQL version environment variable
7265
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
7366

7467
- name: Generate common-nix.vars.pkr.hcl
7568
run: |
76-
curl -L https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_arm64 -o yq
77-
chmod +x yq
69+
curl -L https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_arm64 -o yq && chmod +x yq
7870
PG_VERSION=$(./yq '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
7971
PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
8072
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
8173
echo 'postgres-major-version = "'$POSTGRES_MAJOR_VERSION'"' >> common-nix.vars.pkr.hcl
82-
# echo 'postgresql_major = "'$POSTGRES_MAJOR_VERSION'"' >> common-nix.vars.pkr.hcl
8374
# Ensure there's a newline at the end of the file
8475
echo "" >> common-nix.vars.pkr.hcl
8576
86-
77+
# TODO (darora): not quite sure why I'm having to uninstall and re-install these deps, but the build fails w/o this
8778
- name: Install dependencies
8879
run: |
8980
sudo apt-get update
@@ -95,11 +86,7 @@ jobs:
9586
make init
9687
GIT_SHA=${{github.sha}}
9788
export PACKER_LOG=1
98-
packer build -var "git_sha=$(UPSTREAM_NIX_GIT_SHA)" -var-file="common-nix.vars.pkr.hcl" qemu-arm64-nix.pkr.hcl
99-
100-
- name: Install dependencies
101-
run: |
102-
ls -lh output-cloudimg/
89+
packer build -var "git_sha=${GIT_SHA}" -var-file="common-nix.vars.pkr.hcl" qemu-arm64-nix.pkr.hcl
10390
10491
- name: Grab release version
10592
id: process_release_version
@@ -122,21 +109,21 @@ jobs:
122109
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
123110
aws-region: "us-east-1"
124111

125-
- uses: docker/setup-buildx-action@v3
126-
127-
- name: Login to ECR
128-
uses: docker/login-action@v2
112+
- name: Login to Amazon ECR Public
113+
id: login-ecr-public
114+
uses: aws-actions/amazon-ecr-login@v2
129115
with:
130-
registry: public.ecr.aws
131-
132-
- id: build
133-
uses: docker/build-push-action@v5
134-
with:
135-
file: Dockerfile-kubernetes
136-
push: true
137-
tags: public.ecr.aws/w9p6e7k7/supabase/postgres-v3:${{ steps.process_release_version.outputs.version }}
138-
platforms: linux/arm64
139-
context: .
116+
registry-type: public
117+
118+
- name: Build, tag, and push docker image to Amazon ECR Public
119+
env:
120+
REGISTRY: public.ecr.aws/w9p6e7k7
121+
REGISTRY_ALIAS: supabase
122+
REPOSITORY: postgres-v3
123+
IMAGE_TAG: ${{ steps.process_release_version.outputs.version }}
124+
run: |
125+
docker build -f Dockerfile-kubernetes -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
126+
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
140127
141128
# - name: Upload software manifest to s3 staging
142129
# run: |

ansible/tasks/setup-postgres.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
shell: |
274274
mkdir -p /run/postgresql
275275
chown -R postgres:postgres /run/postgresql
276-
when: stage2_nix and qemu_mode
276+
when: stage2_nix and qemu_mode is defined
277277

278278
- name: Restart Postgres Database without Systemd
279279
become: yes

qemu_artifact.md

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,9 @@
11
# QEMU artifact
22

3-
We build a container image that contains a QEMU qcow2 disk image. This container image can be use with KubeVirt's [containerDisk](https://kubevirt.io/user-guide/storage/disks_and_volumes/#containerdisk) functionality to boot up VMs off the qcow2 image.
4-
5-
Container images are a convenient mechanism to ship the disk image to the nodes where they're needed.
3+
We build a container image that contains a QEMU qcow2 disk image. Container images are a convenient mechanism to ship the disk image to the nodes where they're needed.
64

75
Given the size of the image, the first VM using it on a node might take a while to come up, while the image is being pulled down. The image can be pre-fetched to avoid this; we might also switch to other deployment mechanisms in the future.
86

9-
# Building QEMU artifact
10-
11-
## Creating a bare-metal instance
12-
13-
We launch an Ubuntu 22 bare-metal instance; we're using the `c6g.metal` instance type in this case, but any ARM instance type is sufficient for our purposes. In the example below the region used is: `ap-south-1`.
14-
15-
```bash
16-
# create a security group for your instance
17-
aws ec2 create-security-group --group-name "launch-wizard-1" --description "launch-wizard-1 created 2024-11-26T00:32:56.039Z" --vpc-id "insert-vpc-id"
18-
19-
# using the generated security group ID (insert-sg-group), ensure that it allows for SSH access
20-
aws ec2 authorize-security-group-ingress --group-id "insert-sg-group" --ip-permissions '{"IpProtocol":"tcp","FromPort":22,"ToPort":22,"IpRanges":[{"CidrIp":"0.0.0.0/0"}]}'
21-
22-
# spin up your instance with the generated security group ID (insert-sg-group)
23-
aws ec2 run-instances \
24-
--image-id "ami-0a87daabd88e93b1f" \
25-
--instance-type "c6g.metal" \
26-
--key-name "INSERT_KEY_PAIR_NAME" \ # create a key pair, or use other mechanism of getting on to the box
27-
--block-device-mappings '{"DeviceName":"/dev/sda1","Ebs":{"Encrypted":false,"DeleteOnTermination":true,"Iops":3000,"SnapshotId":"snap-0fe84a34403e3da8b","VolumeSize":200,"VolumeType":"gp3","Throughput":125}}' \
28-
--network-interfaces '{"AssociatePublicIpAddress":true,"DeviceIndex":0,"Groups":["insert-sg-group"]}' \
29-
--tag-specifications '{"ResourceType":"instance","Tags":[{"Key":"Name","Value":"qemu-pg-image"}]}' \
30-
--metadata-options '{"HttpEndpoint":"enabled","HttpPutResponseHopLimit":2,"HttpTokens":"required"}' \
31-
--private-dns-name-options '{"HostnameType":"ip-name","EnableResourceNameDnsARecord":true,"EnableResourceNameDnsAAAARecord":false}' \
32-
--count "1"
33-
34-
```
35-
## Install deps
36-
37-
On the instance, install the dependencies we require for producing QEMU artifacts. Assuming you are the root user:
38-
39-
```bash
40-
apt-get update
41-
apt-get install -y qemu-system qemu-system-arm qemu-utils qemu-efi-aarch64 libvirt-clients libvirt-daemon libqcow-utils software-properties-common git make libnbd-bin nbdkit fuse2fs cloud-image-utils awscli
42-
usermod -aG kvm ubuntu
43-
curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -
44-
apt-add-repository "deb [arch=arm64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
45-
apt-get update && apt-get install packer=1.11.2-1
46-
apt-get install -y docker.io
47-
```
48-
49-
Some dev deps that might be useful:
50-
51-
```bash
52-
apt-get install -y emacs ripgrep vim-tiny byobu
53-
```
54-
55-
## Clone repo and build
56-
57-
Logout/login first to pick up new group memberships!
58-
59-
``` bash
60-
git clone https://github.com/supabase/postgres.git
61-
cd postgres
62-
git checkout da/qemu-rebasing # choose appropriate branch here
63-
make init container-disk-image
64-
```
65-
667
### Build process
678

689
The current AMI process involves a few steps:
@@ -87,21 +28,13 @@ b. packer build (`qemu-arm64-nix.pkr.hcl`)
8728

8829
## Publish image for later use
8930

90-
Following `make init container-disk-image`, the generated image should be found in: `/path/to/postgres/output-cloudimg`. For portability the image is also bundled up as a docker image with the name: `supabase-postgres-test` . Publish the built docker image to a registry of your choosing, and use the published image with KubeVirt.
91-
92-
# Iterating on the QEMU artifact
93-
94-
For a tighter iteration loop on the Postgres artifact, the recommended workflow is to do so on an Ubuntu bare-metal node that's part of the EKS cluster that you're deploying to.
31+
Following `make init alpine-image`, the generated VM image should be bundled as a container image with the name: `supabase-postgres-test` . Publish the built docker image to a registry of your choosing, and use the published image with e.g. KubeVirt.
9532

96-
- Instead of running `make init container-disk-image`, use `make init host-disk` instead to build the raw image file on disk. (`/path/to/postgres/disk/focal-raw.img`)
97-
- Update the VM spec to use `hostDisk` instead of `containerDisk`
98-
- Note that only one VM can use an image at a time, so you can't create multiple VMs backed by the same host disk.
99-
- Enable the `HostDisk` feature flag for KubeVirt
100-
- Deploy the VM to the node
33+
## Iterating on image
10134

102-
Additionally, to iterate on the container image part of things, you can build the image on the bare-metal node (`eks-node-container-disk-image` target), rather than needing to publish it to ECR or similar registry. However, this part can take a while, so iterating using host disks remains the fastest dev loop.
35+
For faster iteration, it's more convenient to build the image on an ubuntu bare-metal node that's part of the EKS cluster you're using. Build the image in the `k8s.io` namespace in order for it to be available for immediate use on that node.
10336

104-
## Dependencies note
37+
### Dependencies note
10538

10639
Installing `docker.io` on an EKS node might interfere with the k8s setup of the node. You can instead install `nerdctl` and `buildkit`:
10740

0 commit comments

Comments
 (0)