From de80b1e43358cecc5c63d7fd80ffa7468266cc8a Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Mon, 15 Feb 2021 23:12:37 -0800 Subject: [PATCH 01/10] mainnet packer provisioner --- .circleci/config.yml | 23 +++++++ tools/packer/LOTUS.txt | 83 +++++++++++++++++++++++ tools/packer/bashrc | 5 ++ tools/packer/lotus.pkr.hcl | 79 +++++++++++++++++++++ tools/packer/scripts/lotus-init.sh | 18 +++++ tools/packer/setup.sh | 49 +++++++++++++ tools/packer/systemd/lotus-daemon.service | 16 +++++ tools/packer/systemd/lotus-init.service | 13 ++++ tools/packer/systemd/lotus-miner.service | 15 ++++ 9 files changed, 301 insertions(+) create mode 100644 tools/packer/LOTUS.txt create mode 100644 tools/packer/bashrc create mode 100644 tools/packer/lotus.pkr.hcl create mode 100755 tools/packer/scripts/lotus-init.sh create mode 100644 tools/packer/setup.sh create mode 100644 tools/packer/systemd/lotus-daemon.service create mode 100644 tools/packer/systemd/lotus-init.service create mode 100644 tools/packer/systemd/lotus-miner.service diff --git a/.circleci/config.yml b/.circleci/config.yml index c5d41fc93fa..1f01c254242 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,6 +2,7 @@ version: 2.1 orbs: go: gotest/tools@0.0.13 aws-cli: circleci/aws-cli@1.3.2 + packer: salaxander/packer@0.0.3 executors: golang: @@ -583,6 +584,18 @@ jobs: docker push $<>/<>:${tag} done + publish-packer: + description: build and push AWS IAM and DigitalOcean droplet. + executor: + name: packer/default + packer-version: 1.6.6 + steps: + - checkout + - attach_workspace: + at: "." + - packer/build: + template: tools/packer/lotus.pkr.hcl + workflows: version: 2.1 ci: @@ -683,3 +696,13 @@ workflows: path: . repo: lotus-dev tag: '${CIRCLE_SHA1:0:8}' + - publish-packer: + requires: + - build-all + filters: + branches: + ignore: + - /.*/ + tags: + only: + - /^v\d+\.\d+\.\d+$/ diff --git a/tools/packer/LOTUS.txt b/tools/packer/LOTUS.txt new file mode 100644 index 00000000000..f756ef8c631 --- /dev/null +++ b/tools/packer/LOTUS.txt @@ -0,0 +1,83 @@ + ,*/((/*,. + ((((((((((((((((((((((((((((* + .((((((((((((((((((((((((((((((((((((((( + ((((((((((((((((((((((((((((((((((((((((((((((( + .((((((((((((((((((((((((((((((((((((((((((((((((((((( + (((((((((((((((((((((((((((((((((((((((((*..,/((((((((((((. + ((((((((((((((((((((((((((((((((((((((, /((/ (((((((((((* + ((((((((((((((((((((((((((((((((((((((. (((((((( (((((((((((((, + .(((((((((((((((((((((((((((((((((((((( ((((((((((((((((((((((((((( + /(((((((((((((((((((((((((((((((((((((/ ((((((((((((((((((((((((((((( + ((((((((((((((((((((((((((((((((((((((/ ,((((((((((((((((((((((((((((((. + /(((((((((((((((((((((((((((((((((((((( ((((((((((((((((((((((((((((((((. + .(((((((((((((((((((((((((( .*//((((( (((((((((((((((((((((((((((((((((( + ((((((((((((((((((((((((((( .,*/(((((((((((((((((((((((((((((/ + (((((((((((((((((((((((((((((((((((((( , ((((((((((((((((((((((((( + *(((((((((((((((((((((((((((((((((((((. (((((((((((((((((((((((((((((((((((( + ((((((((((((((((((((((((((/ .,*((( ((((((((((((((((((((((((((((((((((((( + *(((((((((((((((((((((((((((*,. .,*/((((((((((((((((((((((((((( + (((((((((((((((((((((((((((((((((((/ ((/*,. (((((((((((((((((((((((((( + ((((((((((((((((((((((((((((((((((( ,(((((((((((((((((((((((((((((((((((((/ + (((((((((((((((((((((((((((((((((* (((((((((((((((((((((((((((((((((((((( + *(((((((((((((((((((((((((((((((( (((((((((((((((((((((((((((((((((((((( + *((((((((((((((((((((((((((((((. ((((((((((((((((((((((((((((((((((((((. + ,((((((((((((((((((((((((((((( (((((((((((((((((((((((((((((((((((((( + ((((((((((((((((((((((((((( (((((((((((((((((((((((((((((((((((((( + *(((((((((((((. ((((((( .((((((((((((((((((((((((((((((((((((( + *(((((((((((/ ((, /(((((((((((((((((((((((((((((((((((((. + .((((((((((((((((((((((((((((((((((((((((((((((((((((((((( + ((((((((((((((((((((((((((((((((((((((((((((((((((((* + *(((((((((((((((((((((((((((((((((((((((((((((. + *(((((((((((((((((((((((((((((((((((((. + ((((((((((((((((((((((((((* + + Protocol Labs + + + +Your lotus node is up and running! + +This image contains the two most important pieces of the lotus filecoin suite, the +daemon and the miner. The daemon is is configured to download a snapshot and start +running. In fact, by the time you read this, the daemon may already be in sync. +Go ahead and make sure everything is working correctly with the following commands. + + + +To check if the daemon is running: + + systemctl status lotus-daemon + + + +To check if the daemon is in sync: + + lotus sync status + + + +No wallets are crated by default. You can view, create, and delete wallets wit +the lotus command. Be careful, now. Don't delete a wallet with funds! + + lotus wallet list + lotus wallet new bls + + + +The lotus miner is also installed, but it's not running by default. If you have no +special disk or worker requirements, you can initialize the lotus-miner repo like this: + + sudo -E -u fc lotus-miner init -o + + + +You only need to do this once, after which, you can enable and start the miner. + + sudo systemctl enable lotus-miner + sudo systemctl start lotus-miner + + + +For more information, see https://docs.filecoin.io/ +Found a bug? let us know! https://github.com/filecoin-project/lotus +Chat with us on slack! https://filecoinproject.slack.com/archives/CEGN061C5 diff --git a/tools/packer/bashrc b/tools/packer/bashrc new file mode 100644 index 00000000000..8bda25044be --- /dev/null +++ b/tools/packer/bashrc @@ -0,0 +1,5 @@ +PS1="[\h \w] ⨎ " + +export PROMT_DIRTRIM=1 +export LOTUS_PATH=/var/lib/lotus +export LOTUS_MINER_PATH=/var/lib/lotus-miner diff --git a/tools/packer/lotus.pkr.hcl b/tools/packer/lotus.pkr.hcl new file mode 100644 index 00000000000..329315c072f --- /dev/null +++ b/tools/packer/lotus.pkr.hcl @@ -0,0 +1,79 @@ +locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } + +source "amazon-ebs" "lotus-mainnet" { + ami_name = "lotus-mainnet-${local.timestamp}" + ami_regions = [ + "us-east-1", + "us-west-2", + ] + ami_description = "Lotus Filecoin AMI" + + instance_type = "t2.micro" + source_ami_filter { + filters = { + name = "ubuntu-minimal/images/*ubuntu-focal-20.04-amd64-minimal*" + root-device-type = "ebs" + virtualization-type = "hvm" + } + most_recent = true + owners = ["099720109477"] + } + ssh_username = "ubuntu" +} + +source "digitalocean" "lotus-mainnet" { + droplet_name = "lotus-mainnet" + size = "s-1vcpu-1gb" + region = "nyc3" + image = "ubuntu-20-04-x64" + snapshot_name = "lotus-mainnet-${local.timestamp}" + ssh_username = "root" +} + +build { + sources = [ + "source.amazon-ebs.lotus-mainnet", + "source.digitalocean.lotus-mainnet", + ] + + # Lotus software (from CI workspace) + provisioner "file" { + source = "./linux/lotus" + destination = "lotus" + } + provisioner "file" { + source = "./linux/lotus-miner" + destination = "lotus-miner" + } + # First run script + provisioner "file" { + source = "./tools/packer/scripts/lotus-init.sh" + destination = "lotus-init.sh" + } + # Systemd service units. + provisioner "file" { + source = "./tools/packer/systemd/lotus-daemon.service" + destination = "lotus-daemon.service" + } + provisioner "file" { + source = "./tools/packer/systemd/lotus-miner.service" + destination = "lotus-miner.service" + } + provisioner "file" { + source = "./tools/packer/systemd/lotus-init.service" + destination = "lotus-init.service" + } + provisioner "file" { + source = "./tools/packer/LOTUS.txt" + destination = "LOTUS.txt" + } + provisioner "file" { + source = "./tools/packer/bashrc" + destination = ".bashrc" + } + # build it. + provisioner "shell" { + script = "./tools/packer/setup.sh" + } + +} diff --git a/tools/packer/scripts/lotus-init.sh b/tools/packer/scripts/lotus-init.sh new file mode 100755 index 00000000000..a014f617e23 --- /dev/null +++ b/tools/packer/scripts/lotus-init.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# This script sets up an initial configuraiton for the lotus daemon and miner +# It will only run once. + +GATE="$LOTUS_PATH"/date_initialized + +# Don't init if already initialized. +if [ -f "GATE" ]; then + echo lotus already initialized. + exit 0 +fi + +echo importing minimal snapshot +lotus daemon --import-snapshot https://fil-chain-snapshots-fallback.s3.amazonaws.com/mainnet/minimal_finality_stateroots_latest.car --halt-after-import + +# Block future inits +date > "$GATE" diff --git a/tools/packer/setup.sh b/tools/packer/setup.sh new file mode 100644 index 00000000000..7422aa08890 --- /dev/null +++ b/tools/packer/setup.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# This script is executed by packer to setup the image. +# When this script is run, packer will have already copied binaries into the home directory of +# whichever user it has access too. This script is executed from within the home directory of that +# user. Bear in mind that different cloud providers, and different images on the same cloud +# provider will have a different initial user account. + +set -x + +# Become root, if we aren't already. +# Docker images will already be root. AMIs will have an SSH user account. +UID=$(id -u) +if [ x$UID != x0 ] +then + printf -v cmd_str '%q ' "$0" "$@" + exec sudo su -c "$cmd_str" +fi + +MANAGED_BINS=( lotus lotus-miner lotus-init.sh ) +MANAGED_SYSTEMD=( lotus-daemon.service lotus-miner.service lotus-init.service ) + +# install libs. +apt update +apt -y install libhwloc15 ocl-icd-libopencl1 +ln -s /usr/lib/x86_64-linux-gnu/libhwloc.so.15 /usr/lib/x86_64-linux-gnu/libhwloc.so.5 + +# Create lotus user +useradd -c "lotus system account" -r fc +install -o fc -g fc -d /var/lib/lotus +install -o fc -g fc -d /var/lib/lotus-miner + +# Install software +for i in "${MANAGED_BINS[@]}" +do + install -o root -g root -m 755 -t /usr/local/bin $i + rm $i +done + +# Install systemd units +for i in "${MANAGED_SYSTEMD[@]}" +do + install -o root -g root -m 644 -t /lib/systemd/system $i + rm $i +done + +# Enable services +systemctl daemon-reload +systemctl enable lotus-daemon diff --git a/tools/packer/systemd/lotus-daemon.service b/tools/packer/systemd/lotus-daemon.service new file mode 100644 index 00000000000..a8a6c2f41d9 --- /dev/null +++ b/tools/packer/systemd/lotus-daemon.service @@ -0,0 +1,16 @@ +[Unit] +Description=Lotus Daemon +After=network.target +After=lotus-init.service +Wants=lotus-init.service + +[Service] +User=fc +Group=fc +ExecStart=/usr/local/bin/lotus daemon +Environment=LOTUS_PATH=/var/lib/lotus +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/tools/packer/systemd/lotus-init.service b/tools/packer/systemd/lotus-init.service new file mode 100644 index 00000000000..5a9cb12db16 --- /dev/null +++ b/tools/packer/systemd/lotus-init.service @@ -0,0 +1,13 @@ +[Unit] +Type=oneshot +Description=Sync Lotus chain for the first time + +[Service] +User=fc +Group=fc +ExecStart=/usr/local/bin/lotus-init.sh +Environment=LOTUS_PATH=/var/lib/lotus +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/tools/packer/systemd/lotus-miner.service b/tools/packer/systemd/lotus-miner.service new file mode 100644 index 00000000000..d7289c888b3 --- /dev/null +++ b/tools/packer/systemd/lotus-miner.service @@ -0,0 +1,15 @@ +[Unit] +Description=Lotus Miner +After=network.target + +[Service] +User=fc +Group=fc +ExecStart=/usr/local/bin/lotus-miner run +Environment=LOTUS_PATH=/var/lib/lotus +Environment=LOTUS_MINER_PATH=/var/lib/lotus-miner +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target From cec0a6e790b3d732357b6262390c1932c30be539 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 00:49:07 -0800 Subject: [PATCH 02/10] add calibrationnet --- .circleci/config.yml | 25 ++++++++--- tools/packer/{ => homedir}/LOTUS.txt | 0 tools/packer/{ => homedir}/bashrc | 0 tools/packer/lotus.pkr.hcl | 44 +++++++++++++------ .../scripts/calibrationnet/lotus-init.sh | 20 +++++++++ .../scripts/{ => mainnet}/lotus-init.sh | 0 6 files changed, 68 insertions(+), 21 deletions(-) rename tools/packer/{ => homedir}/LOTUS.txt (100%) rename tools/packer/{ => homedir}/bashrc (100%) create mode 100755 tools/packer/scripts/calibrationnet/lotus-init.sh rename tools/packer/scripts/{ => mainnet}/lotus-init.sh (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1f01c254242..cf7fd13ca38 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -278,6 +278,11 @@ jobs: - install-deps - prepare - run: make calibnet + - run: mkdir linux-calibnet && mv lotus lotus-miner lotus-worker linux-calibnet + - persist_to_workspace: + root: "." + paths: + - linux-calibnet build-lotus-soup: description: | Compile `lotus-soup` Testground test plan @@ -595,6 +600,10 @@ jobs: at: "." - packer/build: template: tools/packer/lotus.pkr.hcl + args: "-var ci_workspace_bins=./linux -var lotus_network=mainnet -var git_tag=$CIRCLE_TAG" + - packer/build: + template: tools/packer/lotus.pkr.hcl + args: "-var ci_workspace_bins=./linux-calibnet -var lotus_network=calibrationnet -var git_tag=$CIRCLE_TAG" workflows: version: 2.1 @@ -699,10 +708,12 @@ workflows: - publish-packer: requires: - build-all - filters: - branches: - ignore: - - /.*/ - tags: - only: - - /^v\d+\.\d+\.\d+$/ + - build-ntwk-calibration + filters: + branches: + ignore: + - /.*/ + tags: + only: + - /^v\d+\.\d+\.\d+$/ + diff --git a/tools/packer/LOTUS.txt b/tools/packer/homedir/LOTUS.txt similarity index 100% rename from tools/packer/LOTUS.txt rename to tools/packer/homedir/LOTUS.txt diff --git a/tools/packer/bashrc b/tools/packer/homedir/bashrc similarity index 100% rename from tools/packer/bashrc rename to tools/packer/homedir/bashrc diff --git a/tools/packer/lotus.pkr.hcl b/tools/packer/lotus.pkr.hcl index 329315c072f..95d93f4aee1 100644 --- a/tools/packer/lotus.pkr.hcl +++ b/tools/packer/lotus.pkr.hcl @@ -1,7 +1,24 @@ -locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } +variable "ci_workspace_bins" { + type = string + default = "./linux" +} + +variable "lotus_network" { + type = string + default = "mainnet" +} -source "amazon-ebs" "lotus-mainnet" { - ami_name = "lotus-mainnet-${local.timestamp}" +variable "git_tag" { + type = string + default = "" +} + +locals { + timestamp = regex_replace(timestamp(), "[- TZ:]", "") +} + +source "amazon-ebs" "lotus" { + ami_name = "lotus-${var.lotus_network}-${var.git_tag}-${local.timestamp}" ami_regions = [ "us-east-1", "us-west-2", @@ -21,33 +38,33 @@ source "amazon-ebs" "lotus-mainnet" { ssh_username = "ubuntu" } -source "digitalocean" "lotus-mainnet" { - droplet_name = "lotus-mainnet" +source "digitalocean" "lotus" { + droplet_name = "lotus-${var.lotus_network}" size = "s-1vcpu-1gb" region = "nyc3" image = "ubuntu-20-04-x64" - snapshot_name = "lotus-mainnet-${local.timestamp}" + snapshot_name = "lotus-${var.lotus_network}-${local.timestamp}" ssh_username = "root" } build { sources = [ - "source.amazon-ebs.lotus-mainnet", - "source.digitalocean.lotus-mainnet", + "source.amazon-ebs.lotus", + "source.digitalocean.lotus", ] # Lotus software (from CI workspace) provisioner "file" { - source = "./linux/lotus" + source = "${var.ci_workspace_bins}/lotus" destination = "lotus" } provisioner "file" { - source = "./linux/lotus-miner" + source = "${var.ci_workspace_bins}/lotus-miner" destination = "lotus-miner" } # First run script provisioner "file" { - source = "./tools/packer/scripts/lotus-init.sh" + source = "./tools/packer/scripts/${var.lotus_network}/lotus-init.sh" destination = "lotus-init.sh" } # Systemd service units. @@ -64,16 +81,15 @@ build { destination = "lotus-init.service" } provisioner "file" { - source = "./tools/packer/LOTUS.txt" + source = "./tools/packer/homedir/LOTUS.txt" destination = "LOTUS.txt" } provisioner "file" { - source = "./tools/packer/bashrc" + source = "./tools/packer/homedir/bashrc" destination = ".bashrc" } # build it. provisioner "shell" { script = "./tools/packer/setup.sh" } - } diff --git a/tools/packer/scripts/calibrationnet/lotus-init.sh b/tools/packer/scripts/calibrationnet/lotus-init.sh new file mode 100755 index 00000000000..d68b3357cc8 --- /dev/null +++ b/tools/packer/scripts/calibrationnet/lotus-init.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script sets up an initial configuraiton for the lotus daemon and miner +# It will only run once. + +GATE="$LOTUS_PATH"/date_initialized + +# Don't init if already initialized. +if [ -f "GATE" ]; then + echo lotus already initialized. + exit 0 +fi + +# Not importing snapshot on calibrationnet. +# +# echo importing minimal snapshot +# lotus daemon --import-snapshot https://fil-chain-snapshots-fallback.s3.amazonaws.com/mainnet/minimal_finality_stateroots_latest.car --halt-after-import + +# Block future inits +date > "$GATE" diff --git a/tools/packer/scripts/lotus-init.sh b/tools/packer/scripts/mainnet/lotus-init.sh similarity index 100% rename from tools/packer/scripts/lotus-init.sh rename to tools/packer/scripts/mainnet/lotus-init.sh From 6b9478f862d8ad67b1cc1acd74ecdb242e295817 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 00:55:04 -0800 Subject: [PATCH 03/10] use sudo for wallet --- tools/packer/homedir/LOTUS.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/packer/homedir/LOTUS.txt b/tools/packer/homedir/LOTUS.txt index f756ef8c631..5ef40685052 100644 --- a/tools/packer/homedir/LOTUS.txt +++ b/tools/packer/homedir/LOTUS.txt @@ -56,11 +56,18 @@ To check if the daemon is in sync: -No wallets are crated by default. You can view, create, and delete wallets wit -the lotus command. Be careful, now. Don't delete a wallet with funds! +To check if the daemon is connecting to other lotus nodes: - lotus wallet list - lotus wallet new bls + lotus net peers + + + +No wallets are crated by default. You can view, create, and delete wallets with +the lotus command. On this image, lotus is running as the user `fc`. +Be careful, now. Don't delete a wallet with funds! + + sudo -E -u fc lotus wallet list + sudo -E -u fc lotus wallet new bls From fca183161a0bbb5297cb6f0a5fc79e77d469c23b Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 07:05:30 -0800 Subject: [PATCH 04/10] use pre exec --- tools/packer/lotus.pkr.hcl | 4 ---- tools/packer/systemd/lotus-daemon.service | 3 +-- tools/packer/systemd/lotus-init.service | 13 ------------- 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 tools/packer/systemd/lotus-init.service diff --git a/tools/packer/lotus.pkr.hcl b/tools/packer/lotus.pkr.hcl index 95d93f4aee1..347cfb9489e 100644 --- a/tools/packer/lotus.pkr.hcl +++ b/tools/packer/lotus.pkr.hcl @@ -76,10 +76,6 @@ build { source = "./tools/packer/systemd/lotus-miner.service" destination = "lotus-miner.service" } - provisioner "file" { - source = "./tools/packer/systemd/lotus-init.service" - destination = "lotus-init.service" - } provisioner "file" { source = "./tools/packer/homedir/LOTUS.txt" destination = "LOTUS.txt" diff --git a/tools/packer/systemd/lotus-daemon.service b/tools/packer/systemd/lotus-daemon.service index a8a6c2f41d9..0c14a4ab06a 100644 --- a/tools/packer/systemd/lotus-daemon.service +++ b/tools/packer/systemd/lotus-daemon.service @@ -1,12 +1,11 @@ [Unit] Description=Lotus Daemon After=network.target -After=lotus-init.service -Wants=lotus-init.service [Service] User=fc Group=fc +ExecStartPre=/usr/local/bin/lotus-init.sh ExecStart=/usr/local/bin/lotus daemon Environment=LOTUS_PATH=/var/lib/lotus Restart=always diff --git a/tools/packer/systemd/lotus-init.service b/tools/packer/systemd/lotus-init.service deleted file mode 100644 index 5a9cb12db16..00000000000 --- a/tools/packer/systemd/lotus-init.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Type=oneshot -Description=Sync Lotus chain for the first time - -[Service] -User=fc -Group=fc -ExecStart=/usr/local/bin/lotus-init.sh -Environment=LOTUS_PATH=/var/lib/lotus -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target From a1b1bb90e8dbe026ac47da9997dab7312c728471 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 07:07:39 -0800 Subject: [PATCH 05/10] extra space --- .circleci/config.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cf7fd13ca38..bdd17b48a34 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -709,11 +709,11 @@ workflows: requires: - build-all - build-ntwk-calibration - filters: - branches: - ignore: - - /.*/ - tags: - only: - - /^v\d+\.\d+\.\d+$/ - + filters: + branches: + ignore: + - /.*/ + tags: + only: + - /^v\d+\.\d+\.\d+$/ + From 857cb815b121f613dac624cdeadcb7660da17f47 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 07:30:11 -0800 Subject: [PATCH 06/10] public AMI --- tools/packer/lotus.pkr.hcl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/packer/lotus.pkr.hcl b/tools/packer/lotus.pkr.hcl index 347cfb9489e..be7f7e1d56a 100644 --- a/tools/packer/lotus.pkr.hcl +++ b/tools/packer/lotus.pkr.hcl @@ -23,6 +23,10 @@ source "amazon-ebs" "lotus" { "us-east-1", "us-west-2", ] + ami_groups = [ + # This causes the ami to be publicly-accessable. + "all", + ] ami_description = "Lotus Filecoin AMI" instance_type = "t2.micro" From 481f17fd55ef33772f474c6f968859e10fe4ed28 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 07:50:40 -0800 Subject: [PATCH 07/10] extra note about downloading the snapshot --- tools/packer/homedir/LOTUS.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/packer/homedir/LOTUS.txt b/tools/packer/homedir/LOTUS.txt index 5ef40685052..7c0f4255e67 100644 --- a/tools/packer/homedir/LOTUS.txt +++ b/tools/packer/homedir/LOTUS.txt @@ -54,6 +54,10 @@ To check if the daemon is in sync: lotus sync status + **note: When starting lotus for the first time, it will download a chain snapshot. + This is a large download and will take several minutes to complete. During + this time, the lotus API will not be up yet. Give it time! You can see + progress by looking at the systemd journal. To check if the daemon is connecting to other lotus nodes: From f697ca7e1eb463abbf3cc62d8ecf30a80e3a9b14 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 17 Feb 2021 08:15:00 -0800 Subject: [PATCH 08/10] remove timeout --- tools/packer/systemd/lotus-daemon.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/packer/systemd/lotus-daemon.service b/tools/packer/systemd/lotus-daemon.service index 0c14a4ab06a..edbc91151d0 100644 --- a/tools/packer/systemd/lotus-daemon.service +++ b/tools/packer/systemd/lotus-daemon.service @@ -7,9 +7,11 @@ User=fc Group=fc ExecStartPre=/usr/local/bin/lotus-init.sh ExecStart=/usr/local/bin/lotus daemon +ExecStop=/usr/local/bin/lotus daemon stop Environment=LOTUS_PATH=/var/lib/lotus Restart=always RestartSec=30 +TimeoutSec=infinity [Install] WantedBy=multi-user.target From 9ceda488e14b714556f40f3df7155bf16500abf8 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Fri, 19 Feb 2021 13:45:59 -0800 Subject: [PATCH 09/10] motd --- tools/packer/etc/motd | 57 +++++++++++++++++++++ tools/packer/homedir/LOTUS.txt | 94 ---------------------------------- tools/packer/lotus.pkr.hcl | 9 +++- tools/packer/setup.sh | 18 +++++-- 4 files changed, 77 insertions(+), 101 deletions(-) create mode 100644 tools/packer/etc/motd delete mode 100644 tools/packer/homedir/LOTUS.txt diff --git a/tools/packer/etc/motd b/tools/packer/etc/motd new file mode 100644 index 00000000000..78e97e1c6da --- /dev/null +++ b/tools/packer/etc/motd @@ -0,0 +1,57 @@ +Your lotus node is up and running! + +This image contains the two most important pieces of the lotus filecoin suite, the +daemon and the miner. The daemon is is configured to download a snapshot and start +running. In fact, by the time you read this, the daemon may already be in sync. +Go ahead and make sure everything is working correctly with the following commands. + + + +To check if the daemon is running: + + systemctl status lotus-daemon + + + +To check if the daemon is in sync: + + lotus sync status + + **note: When starting lotus for the first time, it will download a chain snapshot. + This is a large download and will take several minutes to complete. During + this time, the lotus API will not be up yet. Give it time! You can see + progress by looking at the systemd journal. + + +To check if the daemon is connecting to other lotus nodes: + + lotus net peers + + + +No wallets are crated by default. You can view, create, and delete wallets with +the lotus command. On this image, lotus is running as the user `fc`. +Be careful, now. Don't delete a wallet with funds! + + sudo -E -u fc lotus wallet list + sudo -E -u fc lotus wallet new bls + + + +The lotus miner is also installed, but it's not running by default. If you have no +special disk or worker requirements, you can initialize the lotus-miner repo like this: + + sudo -E -u fc lotus-miner init -o + + + +You only need to do this once, after which, you can enable and start the miner. + + sudo systemctl enable lotus-miner + sudo systemctl start lotus-miner + + + +For more information, see https://docs.filecoin.io/ +Found a bug? let us know! https://github.com/filecoin-project/lotus +Chat with us on slack! https://filecoinproject.slack.com/archives/CEGN061C5 diff --git a/tools/packer/homedir/LOTUS.txt b/tools/packer/homedir/LOTUS.txt deleted file mode 100644 index 7c0f4255e67..00000000000 --- a/tools/packer/homedir/LOTUS.txt +++ /dev/null @@ -1,94 +0,0 @@ - ,*/((/*,. - ((((((((((((((((((((((((((((* - .((((((((((((((((((((((((((((((((((((((( - ((((((((((((((((((((((((((((((((((((((((((((((( - .((((((((((((((((((((((((((((((((((((((((((((((((((((( - (((((((((((((((((((((((((((((((((((((((((*..,/((((((((((((. - ((((((((((((((((((((((((((((((((((((((, /((/ (((((((((((* - ((((((((((((((((((((((((((((((((((((((. (((((((( (((((((((((((, - .(((((((((((((((((((((((((((((((((((((( ((((((((((((((((((((((((((( - /(((((((((((((((((((((((((((((((((((((/ ((((((((((((((((((((((((((((( - ((((((((((((((((((((((((((((((((((((((/ ,((((((((((((((((((((((((((((((. - /(((((((((((((((((((((((((((((((((((((( ((((((((((((((((((((((((((((((((. - .(((((((((((((((((((((((((( .*//((((( (((((((((((((((((((((((((((((((((( - ((((((((((((((((((((((((((( .,*/(((((((((((((((((((((((((((((/ - (((((((((((((((((((((((((((((((((((((( , ((((((((((((((((((((((((( - *(((((((((((((((((((((((((((((((((((((. (((((((((((((((((((((((((((((((((((( - ((((((((((((((((((((((((((/ .,*((( ((((((((((((((((((((((((((((((((((((( - *(((((((((((((((((((((((((((*,. .,*/((((((((((((((((((((((((((( - (((((((((((((((((((((((((((((((((((/ ((/*,. (((((((((((((((((((((((((( - ((((((((((((((((((((((((((((((((((( ,(((((((((((((((((((((((((((((((((((((/ - (((((((((((((((((((((((((((((((((* (((((((((((((((((((((((((((((((((((((( - *(((((((((((((((((((((((((((((((( (((((((((((((((((((((((((((((((((((((( - *((((((((((((((((((((((((((((((. ((((((((((((((((((((((((((((((((((((((. - ,((((((((((((((((((((((((((((( (((((((((((((((((((((((((((((((((((((( - ((((((((((((((((((((((((((( (((((((((((((((((((((((((((((((((((((( - *(((((((((((((. ((((((( .((((((((((((((((((((((((((((((((((((( - *(((((((((((/ ((, /(((((((((((((((((((((((((((((((((((((. - .((((((((((((((((((((((((((((((((((((((((((((((((((((((((( - ((((((((((((((((((((((((((((((((((((((((((((((((((((* - *(((((((((((((((((((((((((((((((((((((((((((((. - *(((((((((((((((((((((((((((((((((((((. - ((((((((((((((((((((((((((* - - Protocol Labs - - - -Your lotus node is up and running! - -This image contains the two most important pieces of the lotus filecoin suite, the -daemon and the miner. The daemon is is configured to download a snapshot and start -running. In fact, by the time you read this, the daemon may already be in sync. -Go ahead and make sure everything is working correctly with the following commands. - - - -To check if the daemon is running: - - systemctl status lotus-daemon - - - -To check if the daemon is in sync: - - lotus sync status - - **note: When starting lotus for the first time, it will download a chain snapshot. - This is a large download and will take several minutes to complete. During - this time, the lotus API will not be up yet. Give it time! You can see - progress by looking at the systemd journal. - - -To check if the daemon is connecting to other lotus nodes: - - lotus net peers - - - -No wallets are crated by default. You can view, create, and delete wallets with -the lotus command. On this image, lotus is running as the user `fc`. -Be careful, now. Don't delete a wallet with funds! - - sudo -E -u fc lotus wallet list - sudo -E -u fc lotus wallet new bls - - - -The lotus miner is also installed, but it's not running by default. If you have no -special disk or worker requirements, you can initialize the lotus-miner repo like this: - - sudo -E -u fc lotus-miner init -o - - - -You only need to do this once, after which, you can enable and start the miner. - - sudo systemctl enable lotus-miner - sudo systemctl start lotus-miner - - - -For more information, see https://docs.filecoin.io/ -Found a bug? let us know! https://github.com/filecoin-project/lotus -Chat with us on slack! https://filecoinproject.slack.com/archives/CEGN061C5 diff --git a/tools/packer/lotus.pkr.hcl b/tools/packer/lotus.pkr.hcl index be7f7e1d56a..a5aac2fe8ff 100644 --- a/tools/packer/lotus.pkr.hcl +++ b/tools/packer/lotus.pkr.hcl @@ -28,6 +28,11 @@ source "amazon-ebs" "lotus" { "all", ] ami_description = "Lotus Filecoin AMI" + launch_block_device_mappings { + device_name = "/dev/sda1" + volume_size = 100 + delete_on_termination = true + } instance_type = "t2.micro" source_ami_filter { @@ -81,8 +86,8 @@ build { destination = "lotus-miner.service" } provisioner "file" { - source = "./tools/packer/homedir/LOTUS.txt" - destination = "LOTUS.txt" + source = "./tools/packer/etc/motd" + destination = "motd" } provisioner "file" { source = "./tools/packer/homedir/bashrc" diff --git a/tools/packer/setup.sh b/tools/packer/setup.sh index 7422aa08890..d7d21664a88 100644 --- a/tools/packer/setup.sh +++ b/tools/packer/setup.sh @@ -18,7 +18,11 @@ then fi MANAGED_BINS=( lotus lotus-miner lotus-init.sh ) -MANAGED_SYSTEMD=( lotus-daemon.service lotus-miner.service lotus-init.service ) +MANAGED_FILES=( + /lib/systemd/system/lotus-daemon.service + /lib/systemd/system/lotus-miner.service + /etc/motd +) # install libs. apt update @@ -37,11 +41,15 @@ do rm $i done -# Install systemd units -for i in "${MANAGED_SYSTEMD[@]}" +# Install systemd and other files. +# Because packer doesn't copy files with root permisison, +# files are in the home directory of the ssh user. Copy +# these files into the right position. +for i in "${MANAGED_FILES[@]}" do - install -o root -g root -m 644 -t /lib/systemd/system $i - rm $i + fn=$(basename $i) + install -o root -g root -m 644 $fn $i + rm $fn done # Enable services From 2f496b3ad781fbdb4fc4d7537e272efac8409fc3 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Mon, 1 Mar 2021 10:11:52 -0800 Subject: [PATCH 10/10] tag in droplet image --- tools/packer/lotus.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/packer/lotus.pkr.hcl b/tools/packer/lotus.pkr.hcl index a5aac2fe8ff..b67e59f7691 100644 --- a/tools/packer/lotus.pkr.hcl +++ b/tools/packer/lotus.pkr.hcl @@ -52,7 +52,7 @@ source "digitalocean" "lotus" { size = "s-1vcpu-1gb" region = "nyc3" image = "ubuntu-20-04-x64" - snapshot_name = "lotus-${var.lotus_network}-${local.timestamp}" + snapshot_name = "lotus-${var.lotus_network}-${var.git_tag}-${local.timestamp}" ssh_username = "root" }