Skip to content

Build and Deploy

Build and Deploy #8

Workflow file for this run

name: Build and Deploy
on:
workflow_dispatch: {}
env:
applicationfolder: GITACTIONSDEPLOYTOAWS
AWS_REGION: eu-west-1
S3BUCKET: codedeploystack-webappdeploymentbucket-1tz0gvfka2owt
jobs:
build:
name: Build and Package
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v2
name: Checkout Repository
- uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: arn:aws:iam::201087200993:role/CodeDeployRoleforGitHub
role-session-name: GithubIAMRoleArn
aws-region: ${{ env.AWS_REGION }}
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: chmod
run: chmod -R +x ./.github
- name: Build and Package Maven
id: package
working-directory: ${{ env.applicationfolder }}
run: $GITHUB_WORKSPACE/.github/scripts/build.sh
- name: Upload Artifact to s3
working-directory: ${{ env.applicationfolder }}/target
run: aws s3 cp *.war s3://${{ env.S3BUCKET }}/
deploy:
needs: build
runs-on: ubuntu-latest
environment: Dev
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v2
- uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::201087200993:role/CodeDeployRoleforGitHub
role-session-name: GithubIAMRoleArn
aws-region: eu-west-1
- run: |
echo "Deploying branch ${{ env.GITHUB_REF }} to ${{ github.event.inputs.environment }}"
commit_hash=`git rev-parse HEAD`
aws deploy create-deployment --application-name CodeDeployAppNameWithASG --deployment-group-name CodeDeployGroupName --github-location repository=$GITHUB_REPOSITORY,commitId=$commit_hash --ignore-application-stop-failures