diff --git a/.github/packer/clean-public-ami.sh b/.github/packer/clean-public-ami.sh deleted file mode 100644 index 4fa50733a18..00000000000 --- a/.github/packer/clean-public-ami.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -echo "Clearing out public ssh keys" - -rm -f /root/.ssh/authorized_keys -rm -f /home/ubuntu/.ssh/authorized_keys diff --git a/.github/packer/create_public_ami.yml b/.github/packer/create_public_ami.yml deleted file mode 100644 index 409b4b30459..00000000000 --- a/.github/packer/create_public_ami.yml +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env ansible-playbook ---- -- name: Create a public AMI image for AWS Marketplace - connection: ssh - gather_facts: false - become: yes - hosts: all - roles: - - name: public-ami diff --git a/.github/packer/roles/public-ami/defaults/main.yml b/.github/packer/roles/public-ami/defaults/main.yml deleted file mode 100644 index 7e5e95f7980..00000000000 --- a/.github/packer/roles/public-ami/defaults/main.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -ava_user: avalanche -ava_group: admin -ava_uid: 1014 -network: mainnet -db_dir: /data/avalanchego -log_dir: /var/log/avalanchego -config_dir: /etc/avalanchego -repo_url: https://github.com/ava-labs/avalanchego -repo_folder: /tmp/avalanchego diff --git a/.github/packer/roles/public-ami/tasks/main.yml b/.github/packer/roles/public-ami/tasks/main.yml deleted file mode 100644 index dad871e1de7..00000000000 --- a/.github/packer/roles/public-ami/tasks/main.yml +++ /dev/null @@ -1,82 +0,0 @@ -- name: Setup gpg key - apt_key: - url: https://downloads.avax.network/avalanchego.gpg.key - state: present - -- name: Setup avalanchego repo - apt_repository: - repo: deb https://downloads.avax.network/apt jammy main - state: present - -- name: Setup golang repo - apt_repository: - repo: ppa:longsleep/golang-backports - state: present - -- name: Install go - apt: - name: golang - state: latest - -- name: Update git clone - git: - repo: "{{ repo_url }}" - dest: "{{ repo_folder }}" - version: "{{ tag }}" - update: yes - force: yes - -- name: Setup systemd - template: - src: templates/avalanchego.service.j2 - dest: /etc/systemd/system/avalanchego.service - mode: 0755 - -- name: Create avalanche user - user: - name: "{{ ava_user }}" - shell: /bin/bash - uid: "{{ ava_uid }}" - group: "{{ ava_group }}" - -- name: Create avalanche config dir - file: - path: /etc/avalanchego - owner: "{{ ava_user }}" - group: "{{ ava_group }}" - state: directory - -- name: Create avalanche log dir - file: - path: "{{ log_dir }}" - owner: "{{ ava_user }}" - group: "{{ ava_group }}" - state: directory - -- name: Create avalanche database dir - file: - path: "{{ db_dir }}" - owner: "{{ ava_user }}" - group: "{{ ava_group }}" - state: directory - -- name: Build avalanchego - command: ./scripts/build.sh - args: - chdir: "{{ repo_folder }}" - -- name: Copy avalanchego binaries to the correct location - command: cp build/avalanchego /usr/local/bin/avalanchego - args: - chdir: "{{ repo_folder }}" - -- name: Configure avalanche - template: - src: templates/conf.json.j2 - dest: /etc/avalanchego/conf.json - mode: 0644 - -- name: Enable Avalanche - systemd: - name: avalanchego - enabled: yes diff --git a/.github/packer/roles/public-ami/templates/avalanchego.service.j2 b/.github/packer/roles/public-ami/templates/avalanchego.service.j2 deleted file mode 100644 index 37e1401622b..00000000000 --- a/.github/packer/roles/public-ami/templates/avalanchego.service.j2 +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Avalanche go client -After=syslog.target network.target - -[Service] -User=avalanche -Type=simple -Environment=HOME=/home/avalanche -ExecStart=/usr/local/bin/avalanchego --config-file /etc/avalanchego/conf.json -KillMode=process -KillSignal=SIGINT -TimeoutStopSec=90 -Restart=on-failure -RestartSec=10s -LimitNOFILE=65000 - -[Install] -WantedBy=multi-user.target diff --git a/.github/packer/roles/public-ami/templates/conf.json.j2 b/.github/packer/roles/public-ami/templates/conf.json.j2 deleted file mode 100644 index 43825438c7c..00000000000 --- a/.github/packer/roles/public-ami/templates/conf.json.j2 +++ /dev/null @@ -1,9 +0,0 @@ -{ - "api-keystore-enabled": false, - "http-host": "0.0.0.0", - "log-dir": "{{ log_dir }}", - "db-dir": "{{ db_dir }}", - "api-admin-enabled": false, - "public-ip-resolution-service": "opendns", - "network-id": "{{ network }}" -} diff --git a/.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl b/.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl deleted file mode 100644 index c319e87134c..00000000000 --- a/.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl +++ /dev/null @@ -1,81 +0,0 @@ -packer { - required_plugins { - amazon = { - source = "github.com/hashicorp/amazon" - version = "~> 1" - } - ansible = { - source = "github.com/hashicorp/ansible" - version = "~> 1" - } - } -} - -variable "skip_create_ami" { - type = string - default = "${env("SKIP_CREATE_AMI")}" -} - -variable "tag" { - type = string - default = "${env("TAG")}" -} - -variable "version" { - type = string - default = "jammy-22.04" -} - -data "amazon-ami" "autogenerated_1" { - filters = { - architecture = "x86_64" - name = "ubuntu/images/*ubuntu-${var.version}-*-server-*" - root-device-type = "ebs" - virtualization-type = "hvm" - } - most_recent = true - owners = ["099720109477"] - region = "us-east-1" -} - -locals { - skip_create_ami = var.skip_create_ami == "True" - timestamp = regex_replace(timestamp(), "[- TZ:]", "") - clean_name = regex_replace(timestamp(), "[^a-zA-Z0-9-]", "-") -} - -source "amazon-ebs" "autogenerated_1" { - ami_groups = ["all"] - ami_name = "public-avalanche-ubuntu-${var.version}-${var.tag}-${local.timestamp}" - instance_type = "c5.large" - region = "us-east-1" - skip_create_ami = local.skip_create_ami - source_ami = "${data.amazon-ami.autogenerated_1.id}" - ssh_username = "ubuntu" - tags = { - Base_AMI_Name = "{{ .SourceAMIName }}" - Name = "public-avalanche-ubuntu-${var.version}-${var.tag}-${local.clean_name}" - Release = "${var.version}" - } -} - -build { - sources = ["source.amazon-ebs.autogenerated_1"] - - provisioner "shell" { - inline = ["while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", "wait_apt=$(ps aux | grep apt | wc -l)", "while [ \"$wait_apt\" -gt \"1\" ]; do echo \"waiting for apt to be ready....\"; wait_apt=$(ps aux | grep apt | wc -l); sleep 5; done", "sudo apt-get -y update", "sudo apt-get install -y python3-boto3 golang"] - } - - provisioner "ansible" { - extra_arguments = ["-e", "component=public-ami build=packer os_release=jammy tag=${var.tag}"] - playbook_file = ".github/packer/create_public_ami.yml" - roles_path = ".github/packer/roles/" - use_proxy = false - } - - provisioner "shell" { - execute_command = "sudo bash -x {{ .Path }}" - script = ".github/packer/clean-public-ami.sh" - } - -} diff --git a/.github/workflows/amichange.json b/.github/workflows/amichange.json deleted file mode 100644 index 9ede5621b00..00000000000 --- a/.github/workflows/amichange.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "Version": { - "VersionTitle": "", - "ReleaseNotes": "Automated latest avalanchego release" - }, - "DeliveryOptions": [ - { - "Details": { - "AmiDeliveryOptionDetails": { - "AmiSource": { - "AmiId": "", - "AccessRoleArn": "", - "UserName": "ubuntu", - "OperatingSystemName": "UBUNTU", - "OperatingSystemVersion": "Ubuntu 22.04" - }, - "UsageInstructions": "Connect via SSH and you can make local calls to port 9650", - "RecommendedInstanceType": "c5.2xlarge", - "SecurityGroups": [ - { - "IpProtocol": "tcp", - "FromPort": 9651, - "ToPort": 9651, - "IpRanges": [ - "0.0.0.0/0" - ] - }, - { - "IpProtocol": "tcp", - "FromPort": 22, - "ToPort": 22, - "IpRanges": [ - "0.0.0.0/0" - ] - } - ] - } - } - } - ] -} - diff --git a/.github/workflows/build-public-ami.yml b/.github/workflows/build-public-ami.yml deleted file mode 100644 index bfb1629e425..00000000000 --- a/.github/workflows/build-public-ami.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: build-public-ami - -on: - workflow_dispatch: - inputs: - tag: - description: 'Tag to create AMI from' - required: true - push: - tags: - - "*" - -env: - PACKER_VERSION: "1.10.2" - PYTHON3_BOTO3_VERSION: "1.20.34+dfsg-1" - -jobs: - build-public-ami-and-upload: - runs-on: ubuntu-22.04 - timeout-minutes: 45 - permissions: - id-token: write - contents: read - - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup-go-for-project - - run: go version - - - name: Install aws cli - run: | - sudo apt update - sudo apt-get -y install python3-boto3="${PYTHON3_BOTO3_VERSION}" - - - name: Get the tag - id: get_tag - run: | - if [[ ${{ github.event_name }} == 'push' ]]; - then - echo "TAG=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_ENV" - else - echo "TAG=${{ inputs.tag }}" >> "$GITHUB_ENV" - fi - shell: bash - - - name: Set whether to skip ami creation in packer - run: | - if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - echo "Setting SKIP_CREATE_AMI to False" - echo "SKIP_CREATE_AMI=False" >> "$GITHUB_ENV" - fi - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: ${{ secrets.AWS_MARKETPLACE_SA_ROLE_ARN }} - role-session-name: githubrolesession - aws-region: us-east-1 - - - name: Setup `packer` - uses: hashicorp/setup-packer@main - id: setup - with: - version: ${{ env.PACKER_VERSION }} - - - name: Run `packer init` - id: init - run: "packer init ./.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl" - - - name: Run `packer validate` - id: validate - run: "packer validate ./.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl" - - - name: Create AMI and upload to marketplace - run: | - ./.github/workflows/update-ami.py - env: - TAG: ${{ env.TAG }} - PRODUCT_ID: ${{ secrets.MARKETPLACE_PRODUCT }} - ROLE_ARN: ${{ secrets.MARKETPLACE_ROLE }} diff --git a/.github/workflows/update-ami.py b/.github/workflows/update-ami.py deleted file mode 100755 index 95360c553d3..00000000000 --- a/.github/workflows/update-ami.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python3 -import json -import os -import boto3 -import uuid -import re -import subprocess -import sys - -# Globals -amifile = '.github/workflows/amichange.json' -packerfile = ".github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl" - -# Environment Globals -product_id = os.getenv('PRODUCT_ID') -role_arn = os.getenv('ROLE_ARN') -vtag = os.getenv('TAG') -tag = vtag.replace('v', '') -skip_create_ami = os.getenv('SKIP_CREATE_AMI', "True") - -def packer_build(packerfile): - print("Running the packer build") - output = subprocess.run('/usr/local/bin/packer build ' + packerfile, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if output.returncode != 0: - raise RuntimeError(f"Command returned with code: {output.returncode}") - -def packer_build_update(packerfile): - print("Creating packer AMI image for Marketplace") - output = subprocess.run('/usr/local/bin/packer build ' + packerfile, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if output.returncode != 0: - raise RuntimeError(f"Command returned with code: {output.returncode}") - - found = re.findall('ami-[a-z0-9]*', str(output.stdout)) - - if found: - amiid = found[-1] - return amiid - else: - raise RuntimeError(f"No AMI ID found in packer output: {output.stdout}") - -def parse_amichange(amifile, amiid, role_arn, tag): - # Create json blob to submit with the catalog update - print("Updating the json artifact with recent amiid and tag information") - with open(amifile, 'r') as file: - data = json.load(file) - - data['DeliveryOptions'][0]['Details']['AmiDeliveryOptionDetails']['AmiSource']['AmiId']=amiid - data['DeliveryOptions'][0]['Details']['AmiDeliveryOptionDetails']['AmiSource']['AccessRoleArn']=role_arn - data['Version']['VersionTitle']=tag - return json.dumps(data) - -def update_ami(amifile, amiid): - # Update the catalog with the last amiimage - print('Updating the marketplace image') - client = boto3.client('marketplace-catalog',region_name='us-east-1') - uid = str(uuid.uuid4()) - global tag - global product_id - global role_arn - - try: - response = client.start_change_set( - Catalog='AWSMarketplace', - ChangeSet=[ - { - 'ChangeType': 'AddDeliveryOptions', - 'Entity': { - 'Type': 'AmiProduct@1.0', - 'Identifier': product_id - }, - 'Details': parse_amichange(amifile,amiid,role_arn,tag), - 'ChangeName': 'Update' - }, - ], - ChangeSetName='AvalancheGo Update ' + tag, - ClientRequestToken=uid - ) - print(response) - except client.exceptions.ResourceInUseException: - print("The product is currently blocked by Amazon. Please check the product site for more details") - except Exception as e: - print(f"An error occurred while updating AMI delivery options: {e}") - -def main(): - try: - if skip_create_ami == "True": - packer_build(packerfile) - else: - update_ami(amifile, packer_build_update(packerfile)) - - print("Ran packer build and update ami successfully") - except Exception as e: - print(f"An error occurred while running packer") - sys.exit(5) - -if __name__ == '__main__': - main() -