Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Django module for one-off management commands #2

Merged
merged 27 commits into from
Apr 8, 2019
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a7d1ab
Scaffold Python package and move over source code
Feb 27, 2019
3dd7116
Add PR template and test artifacts
Feb 27, 2019
a35b00e
Adjust ecsmanage command to read configuration values
Feb 27, 2019
dbe4a70
Get ecsmanage command working
Feb 28, 2019
159e654
Make management command installable
Feb 28, 2019
a46dc8d
Initialize tests
Feb 28, 2019
b2e542c
Draft simple README
Feb 28, 2019
4096b3f
Add Travis config and drop support for py2.7 + py3.5
Feb 28, 2019
f42609d
Clean up Travis config
Feb 28, 2019
f929023
Document workarounds in .travis.yml
jeancochrane Mar 2, 2019
80c3ba5
Clean up README
jeancochrane Mar 2, 2019
0aff8d3
Specify Python 3.6+ support
jeancochrane Mar 2, 2019
6c031a8
Use AWS region name for Boto3 clients
jeancochrane Mar 2, 2019
cc8ecbb
Update setup.py to reflect Python 3.6+ requirement
jeancochrane Mar 2, 2019
1aeac5d
Make sure scripts/update can run in one pass
rbreslow Mar 13, 2019
004ebee
Satisfy linter requirements
rbreslow Mar 13, 2019
8ab47fa
Only pass networkConfiguration for awsvpc network mode
rbreslow Mar 14, 2019
0156d2d
fixup! Only pass networkConfiguration for awsvpc network mode
rbreslow Mar 14, 2019
0dfcaf7
Use setuptools_scm to manage Python package version
rbreslow Mar 14, 2019
94a7ccb
Fix README
hectcastro Apr 6, 2019
0433873
Add support for Black
hectcastro Apr 6, 2019
aa4e0d9
Relax all Black version constraints
hectcastro Apr 6, 2019
cfb5714
Publish to PyPi using azavea user
rbreslow Apr 8, 2019
df23ccb
Single self.stdout.write() call
rbreslow Apr 8, 2019
88b5dfa
Remove moto
rbreslow Apr 8, 2019
e7ac83c
Update MANIFEST.in
rbreslow Apr 8, 2019
fa21255
Remove deploys on develop because untagged scm version violates PEP 4…
rbreslow Apr 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Draft simple README
Draft basic instructions for setup and development in a README.
  • Loading branch information
Jean Cochrane committed Feb 28, 2019
commit b2e542c7d4ce92ac79ebba080d5c037d4994bcdb
135 changes: 134 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,137 @@ other management command on an AWS Elastic Container Service
(ECS) cluster.

Useful for running migrations and other one-off commands in staging and
production environments.
production environments. With `django-ecsmanage`, you can easily run migrations
on a remote cluster from the command line:

```
$ django-admin ecsmanage migrate
```

## Contents

- [Installation](#installation)
- [Configuration](#configuration)
- [Environments](#environments)
- [AWS Resources](#aws-resources)
- [Developing](#developing)

## Installation

Install from GitHub using pip:

```
$ pip install git+https://github.com/azavea/django-ecsmanage.git
```

Update `INSTALLED_APPS` in your Django settings to install the app:

```python
INSTALLED_APPS = (
...
'ecsmanage',
)
```

## Configuration

Settings for the management command are kept in a single configuration
rbreslow marked this conversation as resolved.
Show resolved Hide resolved
dictionary in your Django settings named `ECSMANAGE_ENVIRONMENTS`. Each entry in
`ECSMANAGE_ENVIRONMENTS` should be a key-value pair corresponding to a
named environment (like `default` or `production`) and a set of AWS resources
in that environment. For example:

```python
ECSMANAGE_ENVIRONMENTS = {
'default': {
'TASK_DEFINITION_NAME': 'StagingAppCLI',
'CLUSTER_NAME': 'ecsStagingCluster',
'LAUNCH_TYPE': 'FARGATE',
'SECURITY_GROUP_TAGS': {
'Name': 'sgAppEcsService',
'Environment': 'Staging',
'Project': 'ProjectName'
},
'SUBNET_TAGS': {
'Name': 'PrivateSubnet',
'Environment': 'Staging',
'Project': 'ProjectName'
},
'AWS_REGION': 'us-east-1',
},
}
```

### Environments

The key name for an environment can be any string. You can use this name
with the `--env` flag when running the command to run a command on a
different environment. Take this `ECSMANAGE_ENVIRONMENTS` variable
as an example:

```python
ECSMANAGE_ENVIRONMENTS = {
'default': {
'TASK_DEFINITION_NAME': 'StagingAppCLI',
'CLUSTER_NAME': 'ecsStagingCluster',
'SECURITY_GROUP_TAGS': {
'Name': 'sgStagingAppEcsService',
},
'SUBNET_TAGS': {
'Name': 'StagingPrivateSubnet',
},
},
'production': {
'TASK_DEFINITION_NAME': 'ProductionAppCLI',
'CLUSTER_NAME': 'ecsProductionCluster',
'SECURITY_GROUP_TAGS': {
'Name': 'sgProductionAppEcsService',
},
'SUBNET_TAGS': {
'Name': 'ProductionPrivateSubnet',
},
},
}
```

Using the above settings, you could run production migrations with the
following command:

```
$ django-admin ecsmanage --env production migrate
```

If the `--env` argument is not present, the command will default to the
environment named `default`.

### AWS Resources

The following keys in an environment help the management command locate
the appropriate AWS resources for your cluster:

| key name | description | default |
| -------- | ----------- | ------- |
| `TASK_DEFINITION_NAME` | The name of your ECS task definition. The command will automatically retrieve the latest definition. | |
| `CLUSTER_NAME` | The name of your ECS cluster. | |
| `SECURITY_GROUP_TAGS` | A dictionary of tags to use to identify a security group for your task. | |
| `SUBNET_TAGS` | A dictionary of tags to use to identify a subnet for your task. | |
| `LAUNCH_TYPE` | The ECS launch type for your task. | `FARGATE` |
| `AWS_REGION` | The AWS region to run your task. | `us-east-1` |

## Developing

Local development is managed with Python virtual environments. Make sure that
you have [Python 3.4+ and pip installed](https://www.python.org/downloads/)
before starting.

Install the development package in a virtual environment:

```
$ ./scripts/update
```

Run the tests:

```
$ ./scripts/test
```