Skip to content

Commit

Permalink
feat: add the ability to pass a flag to the action to create immutabl…
Browse files Browse the repository at this point in the history
…e repositories (#21)

PLATENG-1517
  • Loading branch information
edwinf committed Feb 24, 2021
1 parent cfe4ccb commit ec818fc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ The purpose of Trebuchet is to improve the quality of life for pushing Docker im
tag: ${{ secrets.TAG }}
```

| Paramater | Required | Default | Description |
| action | true | n/a | The command to execute, `push` or `copy` are the currently supported actions. |
| repository | true | n/a | The name of the image in either the local docker or remote registry.
| tag | true | The tag of the image to use when performing the action
| region | false | ENV_VAR | The AWS region to execute against. It will use this property or pull from the AWS_DEFAULT_REGION Environment variable. |
| source-account-id | false | CURRENT_ACCOUNT | The account id of the source AWS account for a pull / copy, if different than the default account id.
| source-role-arn | false | CURRENT_ACCOUNT | The role arn to use when pulling the image from ECR. Only needed when the source role is different from the default environment credentials.
| immutable | false | false | Whether the repository should be created as IMMUTABLE (if not already existing) |
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
tag:
required: true
description: 'The tag of the image to use when performing the action'
immutable:
required: false
description: 'Whether the repository should be created as IMMUTABLE (if not already existing)'
default: 'false'
runs:
using: 'node12'
main: 'dist/index.js'
5 changes: 3 additions & 2 deletions src/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class Copy {
readonly sourceAccountRole: string,
readonly sourceAccountId: string,
readonly repository: string,
readonly tag: string
readonly tag: string,
readonly immutable: boolean
) {}

async execute(): Promise<void> {
Expand Down Expand Up @@ -37,7 +38,7 @@ export class Copy {
await this.PullSourcePackage(sts);

// push
const push = new Push(this.ecrClient, this.repository, this.tag);
const push = new Push(this.ecrClient, this.repository, this.tag, this.immutable);
await push.execute();
}

Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function run(): Promise<void> {
const tag: string = core.getInput('tag');
const sourceAccountId = core.getInput('source-account-id');
const sourceRoleArn = core.getInput('source-role-arn');

const immutable: boolean = (core.getInput('immutable', { required: false }) || 'false') === 'true';
const ecrClient = new aws.ECR();

if (repository === undefined || repository.length === 0) {
Expand All @@ -29,7 +29,7 @@ async function run(): Promise<void> {

switch (action) {
case 'push': {
const push = new Push(ecrClient, repository, tag);
const push = new Push(ecrClient, repository, tag, immutable);
await push.execute();
break;
}
Expand All @@ -44,7 +44,8 @@ async function run(): Promise<void> {
sourceRoleArn,
sourceAccountId,
repository,
tag
tag,
immutable
);
await promote.execute();
break;
Expand Down
5 changes: 3 additions & 2 deletions src/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export class Push {
constructor(
readonly ecrClient: aws.ECR,
readonly repository: string,
readonly tag: string
readonly tag: string,
readonly immutable: boolean
) {}

async execute(): Promise<string> {
const registryUri = await ecrHelper.login(this.ecrClient);
await this.createRepository(this.repository, false);
await this.createRepository(this.repository, this.immutable);

core.info(`pushing ${this.repository}:${this.tag} to default ECR`);
await docker.push(registryUri, this.repository, this.tag);
Expand Down

0 comments on commit ec818fc

Please sign in to comment.