|
| 1 | +# RockSteady CLI |
| 2 | + |
| 3 | +A command-line interface for building and deploying Docker images to AWS ECR and notifying the RockSteady deployment service. This tool is designed to be used in CI/CD environments. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +* Builds Docker images from a local `Dockerfile`. |
| 8 | +* Tags images with git branch, commit SHA, and build number for easy tracking. |
| 9 | +* Pushes images to a specified AWS ECR repository. |
| 10 | +* Notifies a RockSteady server of a new successful build, triggering deployments. |
| 11 | +* Leverages Docker layer caching to speed up builds by reusing layers from previous images on the same branch. |
| 12 | + |
| 13 | +## How it works |
| 14 | + |
| 15 | +The `rocksteady` script has two main subcommands: `build` and `deploy`. |
| 16 | + |
| 17 | +### Build and Push an Image |
| 18 | + |
| 19 | +This command builds the Docker image, tags it, and pushes it to your ECR repository. |
| 20 | + |
| 21 | +```bash |
| 22 | +rocksteady build |
| 23 | +``` |
| 24 | + |
| 25 | +This command will: |
| 26 | + |
| 27 | +1. Authenticate with AWS ECR using the provided credentials. |
| 28 | +2. Attempt to pull the latest image for the current branch to use as a build cache (`--cache-from`). This makes builds faster by reusing unchanged layers. |
| 29 | +3. Build the Docker image from the `Dockerfile` in the current directory. |
| 30 | +4. Tag the image with multiple tags: |
| 31 | + * `:build-<build_num>` |
| 32 | + * `:<branch>-<build_num>` |
| 33 | + * `:<branch>-latest` |
| 34 | + * `:<commit_sha>` |
| 35 | + * `:latest` (if the branch is `master`) |
| 36 | +5. Push all generated tags to the ECR repository. |
| 37 | + |
| 38 | +### Notify RockSteady of a New Build |
| 39 | + |
| 40 | +This command sends a webhook to the RockSteady server to notify it that a new build is available for deployment. |
| 41 | + |
| 42 | +```bash |
| 43 | +rocksteady deploy ROCKSTEADY_URL |
| 44 | +``` |
| 45 | + |
| 46 | +* `ROCKSTEADY_URL`: The URL of the RockSteady server's webhook endpoint. This can also be provided via the `ROCKSTEADY_SERVER` environment variable. |
| 47 | + |
| 48 | +## Configuration |
| 49 | + |
| 50 | +The `rocksteady-cli` is configured entirely through environment variables. The script checks for multiple environment variables for the same configuration. Right now it's being invoked and configured from Altmetric's CircleCI account. |
| 51 | + |
| 52 | +### Required Environment Variables |
| 53 | + |
| 54 | +| Variable | Fallback Variable | Description | |
| 55 | +| ----------------------------- | ----------------------------- | ------------------------------------------------------------------------ | |
| 56 | +| `ROCKSTEADY_PROJECT` | `CIRCLE_PROJECT_REPONAME` | The name of the project in RockSteady. | |
| 57 | +| `ECR_BASE` | | The base URI of your ECR repository (e.g., `123456789012.dkr.ecr.us-east-1.amazonaws.com`). | |
| 58 | +| `ECR_AWS_ACCESS_KEY_ID` | `AWS_ACCESS_KEY_ID` | The AWS access key ID for ECR authentication. | |
| 59 | +| `ECR_AWS_SECRET_ACCESS_KEY` | `AWS_SECRET_ACCESS_KEY` | The AWS secret access key for ECR authentication. | |
| 60 | +| `ECR_AWS_REGION` | | The AWS region where your ECR repository is located. | |
| 61 | +| `CIRCLE_BUILD_NUM` | | The build number, used for tagging. | |
| 62 | +| `CIRCLE_BRANCH` | | The git branch name, used for tagging. | |
| 63 | +| `CIRCLE_SHA1` | | The git commit SHA, used for tagging. | |
| 64 | + |
| 65 | +### Optional Environment Variables |
| 66 | + |
| 67 | +| Variable | Fallback Variable | Description | |
| 68 | +| ----------------------------- | ----------------------------- | ------------------------------------------------------------------------ | |
| 69 | +| `ECR_REPO` | `ROCKSTEADY_PROJECT` | The name of the ECR repository. Defaults to the project name. | |
| 70 | +| `ROCKSTEADY_SERVER` | | The URL for the RockSteady server. Can be overridden by the command line argument in `deploy`. | |
| 71 | +| `CF_ACCESSC_ID` | | Cloudflare Access Client ID for authenticating with the RockSteady webhook. | |
| 72 | +| `CF_ACCESS_SECRET` | | Cloudflare Access Client Secret for authenticating with the RockSteady webhook. | |
| 73 | +| `SIDEKIQ_PRO_TOKEN` | | Build-time variable passed to `docker build`. | |
| 74 | +| `DSUI_GITHUB_TOKEN` | | Build-time variable passed to `docker build`. | |
| 75 | + |
| 76 | +## Usage |
| 77 | + |
| 78 | +Add the `rocksteady` script to your CI/CD pipeline. Here’s an example of how to use it in a CircleCI configuration: |
| 79 | + |
| 80 | +```yaml |
| 81 | +deploy: |
| 82 | + docker: |
| 83 | + - image: altmetric/ci:rocksteady-deploy-latest |
| 84 | + |
| 85 | + auth: |
| 86 | + username: $DOCKERHUB_USERNAME |
| 87 | + password: $DOCKERHUB_PASSWORD |
| 88 | + |
| 89 | + steps: |
| 90 | + - setup_remote_docker: |
| 91 | + version: default |
| 92 | + |
| 93 | + - checkout |
| 94 | + |
| 95 | + - run: |
| 96 | + command: deploy |
| 97 | +``` |
0 commit comments