Skip to content

Commit

Permalink
Try upload ami to us-east-1
Browse files Browse the repository at this point in the history
  • Loading branch information
arianvp committed May 23, 2024
1 parent 2b2f5c9 commit d81aba6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build-upload-ami.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e # v9
- uses: DeterminateSystems/magic-nix-cache-action@eeabdb06718ac63a7021c6132129679a8e22d0c7 # v3
- run: nix build .#legacyAmazonImage
- uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
aws-region: us-east-1 # because t2.nano not available in eu-north-1
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/upload-ami
- run: |
image_info=./result/nix-support/image-info.json
images_bucket=${{ vars.IMAGES_BUCKET }}
image_id=$(nix run .#upload-ami -- \
--image-info "$image_info" \
--prefix "build-upload-ami/" \
--s3-bucket "$images_bucket" | jq -r '.["us-east-1"]')
echo "$image_id"
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e # v9
- uses: DeterminateSystems/magic-nix-cache-action@eeabdb06718ac63a7021c6132129679a8e22d0c7 # v3
- run: nix run nixpkgs#actionlint
- run: nix build .#amazonImage -L --system ${{ matrix.runs-on.system }}
- run: nix flake check -L --system ${{ matrix.runs-on.system }}
17 changes: 12 additions & 5 deletions upload-ami/src/upload_ami/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
from mypy_boto3_ec2.literals import InstanceTypeType


def smoke_test(image_id: str, run_id: str, cancel: bool) -> None:
def smoke_test(
*, image_id: str, instance_type: InstanceTypeType | None, run_id: str, cancel: bool
) -> None:
ec2: EC2Client = boto3.client("ec2")

images = ec2.describe_images(Owners=["self"], ImageIds=[image_id])
assert len(images["Images"]) == 1
image = images["Images"][0]
assert "Architecture" in image
architecture = image["Architecture"]
instance_type: InstanceTypeType
if architecture == "x86_64":
if architecture == "x86_64" and instance_type is None:
instance_type = "t3.nano"
elif architecture == "arm64":
elif architecture == "arm64" and instance_type is None:
instance_type = "t4g.nano"
else:
raise Exception("Unknown architecture: " + architecture)
Expand Down Expand Up @@ -76,10 +77,16 @@ def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--image-id", required=True)
parser.add_argument("--run-id", required=False)
parser.add_argument("--instance-type", required=False, type=str)
parser.add_argument("--cancel", action="store_true", required=False)
args = parser.parse_args()

smoke_test(args.image_id, args.run_id, args.cancel)
smoke_test(
image_id=args.image_id,
instance_type=args.instance_type,
run_id=args.run_id,
cancel=args.cancel,
)


if __name__ == "__main__":
Expand Down

0 comments on commit d81aba6

Please sign in to comment.