-
-
Save Rofram/1df3274daedf756c3497f58a300cc278 to your computer and use it in GitHub Desktop.
AWS Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Amazon ECS | |
on: | |
push: | |
- main | |
- develop | |
pull_request: | |
- main | |
- develop | |
release: | |
types: [created] | |
jobs: | |
ci-go-application: | |
name: CI Go Application | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.16 | |
- name: Run tests the application | |
run: go test ./... -coverprofile=./coverage.out | |
deploy: | |
name: Deploy to AWS | |
runs-on: ubuntu-latest | |
needs: ci-go-application | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: "Get Last Release" | |
id: last_release | |
uses: InsonusK/[email protected] | |
with: | |
myToken: ${{ github.token }} | |
exclude_types: "release" | |
view_top: 1 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.NAME_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
# Build a docker container and | |
# push it to ECR so that it can | |
# be deployed to ECS. | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: .aws/task-definition.json | |
container-name: ${{ secrets.CONTAINER_NAME }} | |
image: ${{ steps.build-image.outputs.image }} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ secrets.NAME_SERVICE }} | |
cluster: ${{ secrets.NAME_CLUSTER }} | |
discord-notification: | |
needs: deploy | |
name: Discord Notification | |
runs-on: ubuntu-latest | |
steps: | |
- uses: sarisia/actions-status-discord@v1 | |
if: always() | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
username: GitHub Eucatur Pricing | |
status: ${{ job.status }} | |
title: ${{ github.workflow }} - ${{ env.RELEASE_VERSION }} | |
description: | | |
${{ steps.last_release.outputs.name }} | ${{ steps.last_release.outputs.tag_name }} | |
${{ steps.last_release.outputs.draft }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment