Skip to content

Latest commit

 

History

History
83 lines (58 loc) · 2.68 KB

README.md

File metadata and controls

83 lines (58 loc) · 2.68 KB

Packer

We use Packer to create VM images on GCP with the latest required software installed. The images are used to create secure VMs for next steps.

How it works

Packer will

  1. create a VM on Google Cloud Platform (GCP)
  2. run our scripts to update and install software (e.g., Docker, Prometheus, ContainerSSH) on the VM
  3. take a snapshot of the VM and store it as an image on GCP
  4. delete the VM

Two images are created:

  • ubuntu-with-docker-image for Gateway VM and Logger VM
  • sacrificial-vm-image for Sacrificial VM

Getting Started

Prerequisite

  • A GCP account
  • Install gcloud CLI and initalize it with gcloud init
  • Install Packer

Setting up Packer for GCP

  1. Init GCP if you haven't

    gcloud auth application-default login
  2. Set up default GCP account

    # Create service account `deployer`
    gcloud iam service-accounts create "$SERVICE_ACCOUNT_NAME" \
      --description="service account for running github actions" \
      --display-name="GitHub Actions" \
      --project "$PROJECT_ID"
    
    gcloud projects add-iam-policy-binding "$PROJECT_ID" \
      --member="serviceAccount:"$SERVICE_ACCOUNT_NAME"@$PROJECT_ID.iam.gserviceaccount.com" \
      --role="roles/compute.instanceAdmin.v1"
    gcloud projects add-iam-policy-binding "$PROJECT_ID" \
      --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
      --role="roles/iam.serviceAccountUser"
    gcloud projects add-iam-policy-binding "$PROJECT_ID" \
      --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
      --role=roles/iap.tunnelResourceAccessor

    For alternative login methods, check out Packer - Authentication.

  3. Initialize Packer at ./packer

    packer init .

Building the images

Run

./run.sh

Images should be built to your default GCP project.

Troubleshooting

  1. You may need to enable some GCP services if it is your first time to use GCP. Follow the links in error logs and enable them.

  2. Flaky packer build -force
    Solution: rerun the command. There are strange errors sometimes and we don't yet know how to solve it :P

  3. Red text in log
    image Answer: It's an expected behavior caused by set -x in our bash scripts!!
    See here