diff --git a/.github/workflows/restart-ecs-containers.yaml b/.github/workflows/restart-ecs-containers.yaml new file mode 100644 index 0000000..56a485d --- /dev/null +++ b/.github/workflows/restart-ecs-containers.yaml @@ -0,0 +1,54 @@ +name: Restart ECS Containers + +run-name: Restart ECS Containers - ${{ inputs.environment }} + +permissions: + id-token: write + contents: read + +on: + workflow_call: + inputs: + environment: + required: true + type: string + cluster: + description: 'ECS cluster to restart' + required: true + type: string + service: + description: 'ECS service to restart' + required: true + type: string + secrets: + AWS_REGION: + required: true + AWS_ROLE_TO_ASSUME_ARN: + required: true + +jobs: + restart-ecs: + name: Restart ECS Containers - ${{ inputs.environment }} + runs-on: ubuntu-latest + environment: + name: ${{ inputs.environment }} + deployment: false + env: + ECS_CLUSTER: ${{ inputs.cluster }} + ECS_SERVICE: ${{ inputs.service }} + steps: + - name: Configure aws credentials + uses: aws-actions/configure-aws-credentials@v6 + with: + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME_ARN }} + role-session-name: GithubActionsSession + aws-region: ${{ secrets.AWS_REGION }} + + - name: Force new ECS deployment + run: | + aws ecs update-service \ + --cluster "$ECS_CLUSTER" \ + --service "$ECS_SERVICE" \ + --force-new-deployment + echo "Restarting $ECS_SERVICE" + aws ecs wait services-stable --cluster "$ECS_CLUSTER" --services "$ECS_SERVICE" diff --git a/.github/workflows/update-ssm-parameter.yaml b/.github/workflows/update-ssm-parameter.yaml new file mode 100644 index 0000000..9f8dbfb --- /dev/null +++ b/.github/workflows/update-ssm-parameter.yaml @@ -0,0 +1,49 @@ +name: Update SSM parameter action + +on: + workflow_call: + inputs: + environment: + required: true + type: string + parameter-name: + description: Full name of the Parameter Store parameter + required: true + type: string + parameter-type: + required: false + type: string + default: String + secrets: + AWS_REGION: + required: true + AWS_ROLE_TO_ASSUME_ARN: + required: true + PARAMETER_VALUE: + required: true + +jobs: + update: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + permissions: + id-token: write + steps: + - name: Configure aws credentials + uses: aws-actions/configure-aws-credentials@v6 + with: + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME_ARN }} + role-session-name: GithubActionsSession + aws-region: ${{ secrets.AWS_REGION }} + - name: Update SSM parameter + env: + PARAMETER_NAME: ${{ inputs.parameter-name }} + PARAMETER_TYPE: ${{ inputs.parameter-type }} + PARAMETER_VALUE: ${{ secrets.PARAMETER_VALUE }} + run: | + if [[ -z "$PARAMETER_VALUE" ]]; then + echo "::error::No value supplied for $PARAMETER_NAME" + exit 1 + fi + aws ssm put-parameter --name "$PARAMETER_NAME" --value "$PARAMETER_VALUE" --type "$PARAMETER_TYPE" --overwrite + echo "Updated $PARAMETER_NAME" diff --git a/README.md b/README.md index fac8662..2caf044 100644 --- a/README.md +++ b/README.md @@ -367,6 +367,37 @@ The upload-to-s3 action with a matrix strategy defined: In the s3 bucket, the objects have been uploaded to the specified location: `backend/lambdaA/feature-new-frontend.zip` and `backend/lambdaB/feature-new-frontend.zip`. +## The `update-ssm-parameter.yaml` workflow has the following steps: + +This workflow overwrites a single AWS Systems Manager Parameter Store value, typically from a GitHub secret or variable. + +1. Arguments + - `environment`: The GitHub environment to run in. + - `parameter-name`: Full name of the parameter. + - `parameter-type`: `String`. Default is `String`. + - secrets: + - `AWS_REGION`: the account region for the aws environment the archive is to be upgraded to. It's easier to maintain if this is only set in one place. + - `AWS_ROLE_TO_ASSUME_ARN`: The ARN for the role assume to run `ssm:PutParameter`. + - `PARAMETER_VALUE`: The value to store. + +2. Steps + - Configure aws credentials + - Update SSM parameter with `aws ssm put-parameter --overwrite`. + +```YAML + update-ssm-parameter: + uses: dvsa/.github/.github/workflows/update-ssm-parameter.yaml@v7 + with: + environment: nonprod + parameter-name: /project/nonprod/client-secret + permissions: + id-token: write + secrets: + AWS_REGION: ${{ secrets.AWS_REGION }} + AWS_ROLE_TO_ASSUME_ARN: ${{ secrets.AWS_ROLE_TO_ASSUME_ARN }} + PARAMETER_VALUE: ${{ secrets.CLIENT_SECRET }} +``` + ## The Java `java-snyk-update.yaml` workflow has the following steps: This workflow can be used to update a Java project within Snyk, typically invoked after a merge has been approved.