diff --git a/README.md b/README.md index f7ce93d..62268f5 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,13 @@ -# 1up-github-actions -Composite GitHub Actions used as shared builds by 1up-team - -## Actions -> ℹ️ Each action is created on a separate branch, referenced using -> `@` sign - -> ⚠️ Composite action branches should be prefixed with `build-` in order to apply -> the branch protection rules - -### AWS ECS Gradle Build Steps -[spring-media/1up-github-actions@build-ecs-gradle](https://github.com/spring-media/1up-github-actions/tree/build-ecs-gradle) - -### Nodejs AWS SAM Build Steps -[spring-media/1up-github-actions@build-nodejs-lambda](https://github.com/spring-media/1up-github-actions/tree/build-nodejs-lambda) - -### AWS Terraform Deploy Steps -[spring-media/1up-github-actions@build-ecs-gradle](https://github.com/spring-media/1up-github-actions/tree/deploy-infrastructure) +spring-media/1up-github-actions@build-ecs-nodejs + +```Composite GitHub Action used as a shared build by 1up-team for Nodejs projects deployed to AWS ECS``` + +### Steps Summary +- setup +- docker build and push +- STG Deploy +- on master + - deploy Docker image + - AWS ECS release + - terraform changes are applied (if any) + - status report diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1a1b079 --- /dev/null +++ b/action.yml @@ -0,0 +1,144 @@ +name: 'build-ecs-nodejs' +author: '1up-team' +description: 'Action to build and release Nodejs & ECS repositories' + +inputs: + pkg-token: + description: 'User token used to integrate with the spring-media GitHub packages for internal libs' + required: true + + docker-image-tag: + description: 'Docker image build tag used when pushing to the 1up AWS ECR' + required: false + default: 'b${{ github.run_number }}-${{ github.sha }}' + docker-registry: + description: 'Docker registry URL used when pushing to the 1up AWS ECR' + required: false + default: '933782373565.dkr.ecr.eu-west-1.amazonaws.com' + + staging: + description: 'Release to staging environment' + required: false + default: 'false' + + up-slack-webhook-url: + description: 'Slack channel webhook URL used when reporting master build status' + required: true + + up-aws-access-key-id: + description: 'AWS access key id secret used to integrate with aws-cli or docker repository' + required: true + up-aws-secret-access-key: + description: 'AWS access secret key secret used to integrate with aws-cli or docker repository' + required: true + + app-path: + description: 'Path to the deployable app directory' + required: false + default: '.' + terraform-module-path: + description: 'Path to the corresponding app terraform directory' + required: false + default: 'terraform' + +runs: + using: composite + steps: + - uses: actions/checkout@v3 + + - name: Setup - Validate Inputs + shell: bash + run: | + [[ "${{ inputs.pkg-token }}" ]] || { echo "input 'pkg-token' cannot be blank"; exit 1; } + + - name: Setup service name + run: | + SERVICE_NAME=${GITHUB_REPOSITORY##*/1up-} + echo "Service name: $SERVICE_NAME" + echo "SERVICE_NAME=$SERVICE_NAME" >> $GITHUB_ENV + shell: bash + + - name: ︎Setup - AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ inputs.up-aws-access-key-id }} + aws-secret-access-key: ${{ inputs.up-aws-secret-access-key }} + aws-region: eu-west-1 + + - name: ECR setup + uses: aws-actions/amazon-ecr-login@v1 + + - name: Docker - build image + shell: bash + working-directory: ${{ inputs.app-path }} + run: | + DOCKER_IMAGE="${{ inputs.docker-registry }}/${{ env.SERVICE_NAME }}:${{ inputs.docker-image-tag }}" + docker build -t $DOCKER_IMAGE . + echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> $GITHUB_ENV + + - name: Docker - push image + shell: bash + run: | + docker push ${{ env.DOCKER_IMAGE }} + + - uses: dorny/paths-filter@v2 + id: infrastructure-changes + with: + filters: | + terraform: + - 'terraform/**' + + - name: deploy infrastructure + if: steps.infrastructure-changes.outputs.terraform == 'true' + uses: spring-media/1up-github-actions@deploy-infrastructure + with: + service-name: ${{ env.SERVICE_NAME }} + pkg-token: ${{ inputs.pkg-token }} + docker-image-tag: ${{ inputs.docker-image-tag }} + staging: ${{ inputs.staging }} + module-path: ${{ inputs.terraform-module-path }} + + - name: Release - on staging + if: ${{ inputs.staging == 'true' && steps.infrastructure-changes.outputs.terraform == 'false' }} + uses: silinternational/ecs-deploy@master + with: + aws_access_key_cmd: --aws-access-key + aws_access_key: ${{ inputs.up-aws-access-key-id }} + aws_secret_key_cmd: --aws-secret-key + aws_secret_key: ${{ inputs.up-aws-secret-access-key }} + cluster_cmd: --cluster + cluster: up-cluster-staging + image_cmd: --image + image: ${{ env.DOCKER_IMAGE }} + region_cmd: --region + region: eu-west-1 + service_name_cmd: --service-name + service_name: ${{ env.SERVICE_NAME }} + timeout_cmd: --timeout + timeout: 600 + + - name: Release - [on master] + if: github.ref == 'refs/heads/master' && steps.infrastructure-changes.outputs.terraform == 'false' + uses: silinternational/ecs-deploy@master + with: + aws_access_key_cmd: '--aws-access-key' + aws_access_key: ${{ inputs.up-aws-access-key-id }} + aws_secret_key_cmd: '--aws-secret-key' + aws_secret_key: ${{ inputs.up-aws-secret-access-key }} + cluster_cmd: '--cluster' + cluster: 'up-cluster-production' + image_cmd: '--image' + image: ${{ env.DOCKER_IMAGE }} + region_cmd: '--region' + region: 'eu-west-1' + service_name_cmd: '--service-name' + service_name: ${{ env.SERVICE_NAME }} + timeout_cmd: '--timeout' + timeout: '600' + + - name: Report - [on master] + if: always() + uses: spring-media/1up-github-actions@send-notifications-test + with: + slack-webhook-url: ${{ inputs.up-slack-webhook-url }} + parent-job-status: ${{ job.status }}