-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chg: fix: small fixes * new: feat: alpha version of new bootstrap approach * chg: docs: update docs * new: feat: add new create command * chg: fix: deprecate some parameters * chg: feat: finalize create command and do some refactor
- Loading branch information
1 parent
2a7af66
commit 42e671e
Showing
19 changed files
with
1,065 additions
and
223 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# How to bootstrap a Dev Space | ||
|
||
This section describes how to bootstrap a Dev Space. | ||
|
||
|
||
## Create a key pair to SSH into the instance | ||
|
||
Now, create a key pair and store it in a file, if you already have a key pair, you can skip this step. | ||
|
||
```bash | ||
$ aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem | ||
``` | ||
|
||
Remember to give the right permissions to the file. | ||
|
||
```bash | ||
$ chmod 400 MyKeyPair.pem | ||
``` | ||
|
||
## Use the CLI to bootstrap a Dev Space | ||
|
||
Download one of the following bootstrap scripts: | ||
- [Bootstrap Script for Arch Linux](https://raw.githubusercontent.com/felipemarinho97/dev-spaces/master/examples/templates/arch.yaml) | ||
|
||
Edit the `key_name` and `instance_profile_arn` fields to match your key pair and instance profile you just created. | ||
|
||
You can also edit the other fields to match your requirements, like the availability zone, the instance type, the EBS volume size, etc. | ||
|
||
Then, you can use the CLI to bootstrap a Dev Space. | ||
|
||
```bash | ||
$ dev-spaces bootstrap --template arch.yaml --name MyDevSpace | ||
``` | ||
|
||
The CLI will take care of creating the Dev Space. | ||
|
||
Once the Dev Space is created, you can use the CLI to start it. | ||
|
||
```bash | ||
$ dev-spaces start -n MyDevSpace --min-cpus 2 --min-memory 4 --max-price 0.08 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Creating a DevSpace | ||
|
||
This document describes how to bootstrap a Dev Space using the command `dev-spaces create`. This new version has a better approach on creating the environment because it's more generic and it's easier to manage. Also, it's much more faster (just take few seconds to bootstap a space) than the previous version. | ||
|
||
## Instance Profile | ||
|
||
There is no need to create an instance profile with EBS permissions because the `start` command will wait until the instance is ready and attach the EBS Volume by itself. You can still specify the instance profile in the create command if you want to. | ||
|
||
## SSH Key Pair | ||
|
||
Make sure you have a SSH key pair in your AWS account. You can see [here](BOOTSTRAPPING.md#create-a-key-pair-to-ssh-into-the-instance) how to create one using the `aws cli`. If you want your key pair to be availiable in all regions, you can follow [this tutorial](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-ssh-key-pair-regions/) from a AWS Support. | ||
|
||
## Creating the Space | ||
|
||
The command below will use the pre-defined template to create an space with Amazon Linux 2022 AMI. | ||
|
||
$ dev-spaces create -n MyAmazonLinux2022 -k MyKeyPair -i ami-034b81f0f1dd96797 | ||
|
||
This AMI have the advantage of supporting running docker inside the Dev Space. | ||
|
||
Once created, you can use the command `dev-spaces start` to start the space. | ||
|
||
$ dev-spaces start -n MyAmazonLinux2022 | ||
|
||
Now, your instance will be available to ssh into from the port `2222`. | ||
|
||
## Command Parameters | ||
|
||
_Parameter_|_Alias_|_Description_|_Example_| | ||
|:--:|:--:|:--:|:--:| | ||
|`--name`|`-n`|The name of the Dev Space|`MyDevSpace`| | ||
|`--key-name`|`-k`|The name of the SSH key pair|`MyKeyPair`| | ||
|`--ami`|`-a`|The AMI ID|`ami-034b81f0f1dd96797`| | ||
|`--prefered-instance-type`|`-t`|The type of the instance|`t2.micro`| | ||
|`--instance-profile-arn`|`-p`|The ARN of the instance profile|`arn:aws:iam::123456789012:instance-profile/MyInstanceProfile`| | ||
|`--custom-host-ami`|-|Custom AMI to use for the host - use this flag in combination with `--custom-startup-script`|`ami-034b81f0f1dd96797`| | ||
|`--custom-startup-script`|-|Custom startup script file to use for the host|`./myscript.sh`| | ||
|`--security-group-ids`|-|A list of IDs of the security groups to use|`sg-12345678`| | ||
|
||
## Troubleshooting | ||
|
||
If for some reason you can't SSH into the instance, you can troubleshoot what's wrong by looking at the logs of the host machine. | ||
|
||
Also, try logging into the instance using the root user (port 2222). | ||
|
||
SSH into the host instance (port 22): | ||
|
||
$ ssh -i MyKeyPair.pem -p 22 ec2-user@<IP_ADDRESS> | ||
ec2-user:~$ cat /var/log/user-data.log | ||
ec2-user:~$ cat /var/log/cloud-init-output.log | ||
ec2-user:~$ cat /var/log/cloud-init.log | ||
|
||
Common problems are user-script failing to run due to wrong filesystem mount type, wrong permissions, etc. | ||
|
||
## Extra: Building a Ultra-Optimized DevSpace | ||
|
||
This section will teach you how to build a DevSpace with a very thin host image, this will make the startup time of the DevSpace much faster and will also reduce the costs of the host EBS volume. | ||
|
||
### Step 1: Create a Host Image | ||
|
||
Clone [this repository](https://github.com/felipemarinho97/packer-images): | ||
|
||
$ git clone https://github.com/felipemarinho97/packer-images | ||
|
||
You will need to install the [packer](https://www.packer.io/) tool, follow the instructions on the [packer website](https://www.packer.io/docs/). | ||
|
||
Make sure your AWS credentials are set up correctly. | ||
|
||
Inside the `packer-images` directory, run the following command to build the host image: | ||
|
||
$ cd packer-images | ||
$ packer build base | ||
|
||
Once the image is built, `packer` will output the AMI ID of the host image on your console. | ||
|
||
### Step 2: Use the base-minimal image to create the optimized DevSpace | ||
|
||
Now, you can use the AMI ID of the `base-minimal` image to create the optimized DevSpace. Also, you will need to provide a startup script compatible with your custom host AMI. You can use [this sample](examples/scripts/startup-script.sh) directly on the create command, or you can create your own startup script. | ||
|
||
```bash | ||
$ dev-spaces create -n MyDevSpace \ | ||
-k MyKeyPair \ | ||
-i <your-devsapce-ami> \ | ||
--custom-host-ami <base-minimal-ami-id> # <-- this is the AMI ID of the image created by packer | ||
--custom-startup-script 'https://raw.githubusercontent.com/felipemarinho97/dev-spaces/master/examples/scripts/startup-script.sh' | ||
|
||
``` | ||
|
||
Done! This optimized DevSpace will take only few seconds to start. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.