contrib/automation/README.rst
author Arseniy Alekseyev <aalekseyev@janestreet.com>
Tue, 20 Sep 2022 18:16:50 -0400
changeset 49512 6939d5ed20e0
parent 43057 c5c502bd1f70
permissions -rw-r--r--
rhg: central treatment of PLAIN and PLAINEXCEPT
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42024
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
====================
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
Mercurial Automation
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
====================
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
This directory contains code and utilities for building and testing Mercurial
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
on remote machines.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
The ``automation.py`` Script
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
============================
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
``automation.py`` is an executable Python script (requires Python 3.5+)
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
that serves as a driver to common automation tasks.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
When executed, the script will *bootstrap* a virtualenv in
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
``<source-root>/build/venv-automation`` then re-execute itself using
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
that virtualenv. So there is no need for the caller to have a virtualenv
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
explicitly activated. This virtualenv will be populated with various
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
dependencies (as defined by the ``requirements.txt`` file).
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
To see what you can do with this script, simply run it::
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
   $ ./automation.py
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
Local State
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
===========
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
By default, local state required to interact with remote servers is stored
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
in the ``~/.hgautomation`` directory.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
We attempt to limit persistent state to this directory. Even when
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
performing tasks that may have side-effects, we try to limit those
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
side-effects so they don't impact the local system. e.g. when we SSH
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
into a remote machine, we create a temporary directory for the SSH
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
config so the user's known hosts file isn't updated.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
43057
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    36
Try Server
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    37
==========
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    38
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    39
There exists a *Try Server* which allows automation to run against
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    40
an arbitrary Mercurial changeset and displays results via the web.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    41
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    42
.. note::
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    43
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    44
   The *Try Server* is still experimental infrastructure.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    45
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    46
To use the *Try Server*::
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    47
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    48
   $ ./automation.py try
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    49
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    50
With a custom AWS profile::
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    51
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    52
   $ AWS_PROFILE=hg contrib/automation/automation.py try
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    53
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    54
By default, the ``.`` revision is submitted. **Any uncommitted changes
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    55
are not submitted.**
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    56
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    57
To switch which revision is used::
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    58
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    59
   $ ./automation.py try -r abcdef
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    60
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    61
Access to the *Try Server* requires access to a special AWS account.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    62
This account is currently run by Gregory Szorc. Here is the procedure
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    63
for accessing the *Try Server*:
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    64
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    65
1. Email Gregory Szorc at gregory.szorc@gmail.com and request a
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    66
   username. This username will be stored in the public domain.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    67
2. Wait for an email reply containing your temporary AWS credentials.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    68
3. Log in at https://gregoryszorc-hg.signin.aws.amazon.com/console
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    69
   and set a new, secure password.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    70
4. Go to https://console.aws.amazon.com/iam/home?region=us-west-2#/security_credentials
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    71
5. Under ``Access keys for CLI, SDK, & API access``, click the
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    72
   ``Create access key`` button.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    73
6. See the ``AWS Integration`` section for instructions on
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    74
   configuring your local client to use the generated credentials.
c5c502bd1f70 automation: add a command to submit to a Try server
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43056
diff changeset
    75
42024
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    76
AWS Integration
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
===============
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    78
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    79
Various automation tasks integrate with AWS to provide access to
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    80
resources such as EC2 instances for generic compute.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    81
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    82
This obviously requires an AWS account and credentials to work.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    83
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    84
We use the ``boto3`` library for interacting with AWS APIs. We do not employ
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    85
any special functionality for telling ``boto3`` where to find AWS credentials. See
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    86
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    87
for how ``boto3`` works. Once you have configured your environment such
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    88
that ``boto3`` can find credentials, interaction with AWS should *just work*.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    89
43056
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    90
To configure ``boto3``, you can use the ``aws configure`` command to
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    91
write out configuration files. (The ``aws`` command is typically provided
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    92
by an ``awscli`` package available in your package manager, including
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    93
``pip``.) Alternatively, you can write out files in ``~/.aws/`` directly.
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    94
e.g.::
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    95
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    96
   # ~/.aws/config
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    97
   [default]
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
    98
   region = us-west-2
42024
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    99
43056
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   100
   # ~/.aws/credentials
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   101
   [default]
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   102
   aws_access_key_id = XXXX
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   103
   aws_secret_access_key = YYYY
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   104
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   105
If you have multiple AWS accounts, you can name the profile something
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   106
different from ``default``. e.g. ``hg``. You can influence which profile
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   107
is used by ``boto3`` by setting the ``AWS_PROFILE`` environment variable.
f71b3c561b93 automation: improve documentation for credentials management
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42907
diff changeset
   108
e.g. ``AWS_PROFILE=hg``.
42024
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   109
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   110
Resource Management
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   111
-------------------
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   112
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   113
Depending on the task being performed, various AWS services will be accessed.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   114
This of course requires AWS credentials with permissions to access these
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   115
services.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   116
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   117
The following AWS services can be accessed by automation tasks:
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   118
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   119
* EC2
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   120
* IAM
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   121
* Simple Systems Manager (SSM)
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   122
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   123
Various resources will also be created as part of performing various tasks.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   124
This also requires various permissions.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   125
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   126
The following AWS resources can be created by automation tasks:
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   127
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   128
* EC2 key pairs
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   129
* EC2 security groups
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   130
* EC2 instances
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   131
* IAM roles and instance profiles
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   132
* SSM command invocations
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   133
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   134
When possible, we prefix resource names with ``hg-`` so they can easily
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   135
be identified as belonging to Mercurial.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   136
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   137
.. important::
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   138
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   139
   We currently assume that AWS accounts utilized by *us* are single
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   140
   tenancy. Attempts to have discrete users of ``automation.py`` (including
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   141
   sharing credentials across machines) using the same AWS account can result
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   142
   in them interfering with each other and things breaking.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   143
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   144
Cost of Operation
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   145
-----------------
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   146
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   147
``automation.py`` tries to be frugal with regards to utilization of remote
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   148
resources. Persistent remote resources are minimized in order to keep costs
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   149
in check. For example, EC2 instances are often ephemeral and only live as long
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   150
as the operation being performed.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   151
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   152
Under normal operation, recurring costs are limited to:
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   153
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   154
* Storage costs for AMI / EBS snapshots. This should be just a few pennies
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   155
  per month.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   156
42285
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   157
When running EC2 instances, you'll be billed accordingly. Default instance
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   158
types vary by operation. We try to be respectful of your money when choosing
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   159
defaults. e.g. for Windows instances which are billed per hour, we use e.g.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   160
``t3.medium`` instances, which cost ~$0.07 per hour. For operations that
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   161
scale well to many CPUs like running Linux tests, we may use a more powerful
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   162
instance like ``c5.9xlarge``. However, since Linux instances are billed
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   163
per second and the cost of running an e.g. ``c5.9xlarge`` for half the time
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   164
of a ``c5.4xlarge`` is roughly the same, the choice is justified.
42024
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   165
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   166
.. note::
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   167
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   168
   When running Windows EC2 instances, AWS bills at the full hourly cost, even
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   169
   if the instance doesn't run for a full hour (per-second billing doesn't
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   170
   apply to Windows AMIs).
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   171
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   172
Managing Remote Resources
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   173
-------------------------
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   174
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   175
Occassionally, there may be an error purging a temporary resource. Or you
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   176
may wish to forcefully purge remote state. Commands can be invoked to manually
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   177
purge remote resources.
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   178
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   179
To terminate all EC2 instances that we manage::
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   180
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   181
   $ automation.py terminate-ec2-instances
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   182
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   183
To purge all EC2 resources that we manage::
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   184
b05a3e28cf24 automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   185
   $ automation.py purge-ec2-resources
42285
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   186
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   187
Remote Machine Interfaces
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   188
=========================
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   189
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   190
The code that connects to a remote machine and executes things is
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   191
theoretically machine agnostic as long as the remote machine conforms to
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   192
an *interface*. In other words, to perform actions like running tests
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   193
remotely or triggering packaging, it shouldn't matter if the remote machine
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   194
is an EC2 instance, a virtual machine, etc. This section attempts to document
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   195
the interface that remote machines need to provide in order to be valid
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   196
*targets* for remote execution. These interfaces are often not ideal nor
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   197
the most flexible. Instead, they have often evolved as the requirements of
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   198
our automation code have evolved.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   199
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   200
Linux
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   201
-----
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   202
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   203
Remote Linux machines expose an SSH server on port 22. The SSH server
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   204
must allow the ``hg`` user to authenticate using the SSH key generated by
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   205
the automation code. The ``hg`` user should be part of the ``hg`` group
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   206
and it should have ``sudo`` access without password prompting.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   207
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   208
The SSH channel must support SFTP to facilitate transferring files from
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   209
client to server.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   210
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   211
``/bin/bash`` must be executable and point to a bash shell executable.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   212
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   213
The ``/hgdev`` directory must exist and all its content owned by ``hg::hg``.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   214
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   215
The ``/hgdev/pyenv`` directory should contain an installation of
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   216
``pyenv``. Various Python distributions should be installed. The exact
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   217
versions shouldn't matter. ``pyenv global`` should have been run so
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   218
``/hgdev/pyenv/shims/`` is populated with redirector scripts that point
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   219
to the appropriate Python executable.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   220
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   221
The ``/hgdev/venv-bootstrap`` directory must contain a virtualenv
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   222
with Mercurial installed. The ``/hgdev/venv-bootstrap/bin/hg`` executable
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   223
is referenced by various scripts and the client.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   224
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   225
The ``/hgdev/src`` directory MUST contain a clone of the Mercurial
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   226
source code. The state of the working directory is not important.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   227
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   228
In order to run tests, the ``/hgwork`` directory will be created.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   229
This may require running various ``mkfs.*`` executables and ``mount``
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   230
to provision a new filesystem. This will require elevated privileges
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   231
via ``sudo``.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   232
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   233
Various dependencies to run the Mercurial test harness are also required.
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   234
Documenting them is beyond the scope of this document. Various tests
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   235
also require other optional dependencies and missing dependencies will
65b3ef162b39 automation: initial support for running Linux tests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42024
diff changeset
   236
be printed by the test runner when a test is skipped.
42907
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   237
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   238
Releasing Windows Artifacts
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   239
===========================
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   240
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   241
The `automation.py` script can be used to automate the release of Windows
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   242
artifacts::
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   243
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   244
   $ ./automation.py build-all-windows-packages --revision 5.1.1
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   245
   $ ./automation.py publish-windows-artifacts 5.1.1
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   246
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   247
The first command will launch an EC2 instance to build all Windows packages
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   248
and copy them into the `dist` directory relative to the repository root. The
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   249
second command will then attempt to upload these files to PyPI (via `twine`)
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   250
and to `mercurial-scm.org` (via SSH).
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   251
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   252
Uploading to PyPI requires a PyPI account with write access to the `Mercurial`
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   253
package. You can skip PyPI uploading by passing `--no-pypi`.
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   254
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   255
Uploading to `mercurial-scm.org` requires an SSH account on that server
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   256
with `windows` group membership and for the SSH key for that account to be the
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   257
default SSH key (e.g. `~/.ssh/id_rsa`) or in a running SSH agent. You can
92593d72e10b automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42285
diff changeset
   258
skip `mercurial-scm.org` uploading by passing `--no-mercurial-scm-org`.