Package: perry-the-docker-agent
Perry The Docker AgentYour cool remote docker agent in the cloud ⛄️Based onremote-docker-aws🙏🏾Use docker to develop services, but without the overhead of running docker on your machine! This is a development tool that you should use if your machine is low performance, or if you are running many docker services.Why is this useful?Frees up your local machine for useful tasks
such as running your code editor, browser, and email, leaving running Docker to a dedicated server instance.
The result is that your local machine functions faster, uses up less disk space, and consumes less power.
MacOS users will also see noticeable speed improvements since Docker on Linux (which is
what the remote hosts runs) is much more performant.The downsides:SSH tunnel communication is slower than local communication. However using an AWS region with low ping makes the latency unnoticeable. Find the region fastest for you usingthis siteSome more setup required to get everything configured properly and running (tunneling ports, syncing file changes)Running the ec2 instance incurs an additional cost over running locally, although a t3.medium instance in Canada only costs just under 5 cents/hourHow it works: two processes are run, a sync and a tunnel process.The sync process keeps local and remote files in sync so that the docker process run remotely can use docker volumes transparentlyThe tunnel process forwards ports needed so your local system can communicate with docker, plus additional ports as required, such as port 443 for browser communicationSetupFirst login to your AWS account andcreate access keys to access AWS through the CLIYou will need the following IAM policies:AmazonEC2FullAccessAWSCloudFormationFullAccessAnd now in your terminal:# Replace dav with your name# You will need to setup an AWS account if you don't have one# and create access key credentialsawsconfigure--profiledavexportAWS_PROFILE=davInstall pre-requisitesHaveHomebrew(Available on both macOS and Linux now!)Havepipxpipinstallperry-the-docker-agent# or.... if part of a projectpoetryaddperry-the-docker-agent# Install unison sync utilitybrewinstallunison# Install file-watcher driver for unison# On MacOS:brewinstallautozimu/homebrew-formulas/unison-fsmonitor# Or, on Linux since the above formula doesn't work:brewinstalleugenmayer/dockersync/unoxGenerate and upload a keypair to AWSperrycreate-key-pairCreate the ec2 instanceperrycreateDaily RunningStart the remote-docker ec2 instanceperrystartThis will automatically switch the docker context for you. If you want to switch
back to the default agent rundocker context use defaultIn one terminal start the tunnel so that the ports you need to connect to are exposedperrytunnelIn another terminal sync file changes to the remote instance:perrysyncDevelop and code! All services should be accessible and usable as usual (eg:docker ps,docker-compose up, etc.)
as long as you are runningperry tunneland are forwarding the ports you needWhen you're done for the day don't forget to stop the instance to save money:perrystopConfig FileLooks for a config file at the path./perry_config.ymlby default,
which can be overriden by passing--config-path.An exampleperry_config.ymlfile:aws_region:af-south-1instance_type:t3.largevolume_size:100sync_dir:./project_id:"ranger"ignore_dirs:-.venv-.git-node_modules-__pycache__remote_port_forwards:local-webpack-app:"8080":"8080"local_port_forwards:user-api:"2020":"2020"blog-api:"3030":"3030"Usage:perry[OPTIONS]COMMAND[ARGS]...╭─Options───────────────────────────────────────────────────────────────────────────────╮
│--config-pathTEXTPathoftheperryconfig│
│[default:./perry_config.yml]│
│--install-completionInstallcompletionforthecurrentshell.│
│--show-completionShowcompletionforthecurrentshell,tocopyitor│
│customizetheinstallation.│
│--helpShowthismessageandexit.│
╰─────────────────────────────────────────────────────────────────────────────────────────╯
╭─Commands──────────────────────────────────────────────────────────────────────────────╮
│createProvisionanewec2instancetouseastheremoteagent│
│create-key-pairCreateanduploadanewkeypairtoAWSforSSHaccess│
│deleteDeletetheprovisionedec2instance│
│sshConnecttotheremoteagentviaSSH│
│startStarttheremoteagentinstance│
│stopStoptheremoteagentinstance│
│syncSyncthegivendirectorieswiththeremoteinstance│
│testTestnewconfig│
│tunnelCreateaSSHtunneltotheremoteinstancetoconnectwiththedocker│
│agentandcontainers│
╰─────────────────────────────────────────────────────────────────────────────────────────╯The current configurable values can be seen inconfig.pyaws_region(takes precedence overAWS_REGIONand.aws/config)The region to create the instance ininstance_typeType of ec2 instance, defaults to:t3.mediumproject_iddefaults toNoneUsed to uniquely identify the instance, this is useful if multiple remote-docker agents
will be created in the same AWS accountkey_pathdefaults to:~/.ssh/id_rsa_perry_{{project_id}}local_port_forwardsdefaults to:{}Object containing label -> port mapping objects for opening the ports on the remote host.
A mapping of"remote_port_forwards": {"my_app": {"80": "8080"}}will open port 80 on your local machine
and point it to port 8080 of the remote-docker instance (which ostensibly a container is listening on).
The name doesn't do anything except help legibility.remote_port_forwardsdefaults to:{}Similar tolocal_port_forwardsexcept will open the port on the remote instance.This is useful to have frontend webpack apps accessible on the remote hostignore_dirsdefaults to:[]list of directories to ignoresync_dirdirectory to sync, will usually be the root fo the projectvolume_sizedefaults to:30(GB)Size of the ec2 volume.CostA t3.medium instance on ca-central-1 currently costs $0.046 /hour.See current pricesNothing else used should incur any cost with reasonable usageNotesSeeperry --helpfor more information on the commands availableThe unison version running on the server and running locally have to
match. If one of them updates to a newer version, you should update the other.Perry improvements onremote-docker-awsPerry is configured to the project by a localperry_config.ymlPerry usespoetry,pydanticandtyperPerry enables swap accounting on the remote ec2 instance which allows docker-compose resource limitsPerry uses a simpler method to sync and ignore directories.