Skip to content

Commit

Permalink
Merge pull request #4 from seek-oss/fix-defaults
Browse files Browse the repository at this point in the history
Fix policy defaults
  • Loading branch information
72636c authored Mar 12, 2019
2 parents 743cbf1 + d574777 commit 570f6f2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 34 deletions.
55 changes: 38 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
# create-ecr-buildkite-plugin
# Create ECR Buildkite Plugin

A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) to create and configure AWS ECR.
[![Build Status](https://img.shields.io/github/release/seek-oss/create-ecr-buildkite-plugin.svg)](https://github.com/seek-oss/create-ecr-buildkite-plugin/releases)

# Example
A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) to create and
manage an Amazon ECR repository.

## Basic Usage
## Example

```yml
The following pipeline creates an ECR repository `my-repo` if it does not
already exist, and sets the lifecycle policy to the default
[policies/default-lifecycle-policy.json](policies/default-lifecycle-policy.json):

```yaml
steps:
- label: ecr
plugins:
- seek-oss/create-ecr#v1.1.2:
name: my-repo
```
A custom lifecycle policy and repository policy may be specified:
```yaml
steps:
- label: 'Main'
- label: ecr
plugins:
seek-oss/create-ecr:
name: 'my-repo-name'
repository-policy: 'path/to/repository-policy.json'
lifecycle-policy: 'path/to/lifecycle-policy.json'
command:
- echo hi
- seek-oss/create-ecr#v1.1.2:
lifecycle-policy: path/to/lifecycle-policy.json
name: my-repo
repository-policy: path/to/repository-policy.json
```
Params:
## Configuration
- `name` (required, string)

Name of the ECR repository.

- `repository-policy` (optional, string)

Path in local repository to the repository policy file.

- `lifecycle-policy` (optional, string)

- name (required) - name of the ECR.
- repository-policy (optional) - path in local repository to the repository policy file.
- lifecycle-policy (optional) - path in local repository to the lifecycle policy file.
Path in local repository to the lifecycle policy file.

# License
## License

MIT (see [LICENSE](LICENSE))
27 changes: 15 additions & 12 deletions hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,44 @@ set -euo pipefail
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

get_ecr_url() {
local repository_name="$1"
local repository_name="${1}"
aws ecr describe-repositories \
--repository-names "${repository_name}" \
--output text \
--query 'repositories[0].repositoryUri'
}

ecr_exists() {
local repository_name="$1"
local repository_name="${1}"
aws ecr describe-repositories \
--repository-names "${repository_name}" \
--output text \
--query 'repositories[0].registryId'
}

upsert_ecr() {
local repository_name="$1"
local repository_name="${1}"
if ! ecr_exists "${repository_name}"; then
echo '--- Creating ECR repository'
echo "Name: ${repository_name}"
aws ecr create-repository --repository-name "${repository_name}"
fi

repository_policy_file="${BUILDKITE_PLUGIN_CREATE_ECR_REPOSITORY_POLICY:-''}"
echo "Policy file: ${repository_policy_file}"
if [ "$repository_policy_file" != "" ]; then
echo 'Setting ECR repository policy'
repository_policy_file="${BUILDKITE_PLUGIN_CREATE_ECR_REPOSITORY_POLICY:-}"
if [[ ${repository_policy_file} != '' ]]; then
echo '--- Setting ECR repository policy'
echo "File: ${repository_policy_file}"
aws ecr set-repository-policy \
--repository-name "${repository_name}" \
--policy-text "file://${repository_policy_file}"
fi

echo 'Setting ECR Lifecycle policy'
lifecycle_policy_file="${BUILDKITE_PLUGIN_CREATE_ECR_LIFECYCLE_POLICY:-'$basedir/policies/default-lifecycle-policy.json'}"
aws ecr put-lifecycle-policy \
--repository-name "${repository_name}" \
--lifecycle-policy-text "file://${lifecycle_policy_file}"
lifecycle_policy_file="${BUILDKITE_PLUGIN_CREATE_ECR_LIFECYCLE_POLICY:-"${basedir}/policies/default-lifecycle-policy.json"}"
echo '--- Setting ECR lifecycle policy'
echo "File: ${lifecycle_policy_file}"
aws ecr put-lifecycle-policy \
--repository-name "${repository_name}" \
--lifecycle-policy-text "file://${lifecycle_policy_file}"
}

$(aws ecr get-login --no-include-email)
Expand Down
10 changes: 5 additions & 5 deletions plugin.yaml → plugin.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: create-ecr
description: Plugin managing creation of AWS ECR
name: Create ECR
description: Create and manage an Amazon ECR repository
author: https://github.com/seek-oss
requirements:
- docker
configuration:
properties:
lifecycle-policy:
type: string
name:
type: string
repository-policy:
type: string
lifecycle-policy:
type: string
required: ["name"]
required: ['name']

0 comments on commit 570f6f2

Please sign in to comment.