fix: env #6
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: AWS CodeDeploy Automation | |
on: | |
push: | |
branches: | |
- "deploy/spring" | |
env: | |
AWS_REGION : "ap-northeast-2" | |
CONTAINER_NAME: "spring-app" | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
Deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.ROLE_NAME }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build docker file and setting deploy files | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
- name: Prepare appspec.yml | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
sed -i "s/<AWS_REGION>/${{ env.AWS_REGION }}/g" scripts/start_docker.sh | |
sed -i "s/<CONTAINER_NAME>/${{ env.CONTAINER_NAME }}/g" scripts/start_docker.sh | |
sed -i "s/<ECR_REGISTRY>/$ECR_REGISTRY/g" scripts/start_docker.sh | |
sed -i "s/<ECR_REPOSITORY>/$ECR_REPOSITORY/g" scripts/start_docker.sh | |
sed -i "s/<IMAGE_TAG>/$IMAGE_TAG/g" scripts/start_docker.sh | |
sed -i "s/<CONTAINER_NAME>/${{ env.CONTAINER_NAME }}/g" scripts/stop_docker.sh | |
sed -i "s/<CONTAINER_NAME>/${{ env.CONTAINER_NAME }}/g" scripts/validate_service.sh | |
- name: Make .zip | |
run: | | |
zip -r deployment_package.zip ./scripts/* appspec.yml | |
- name: Upload .zip to Amazon S3 | |
run: | | |
aws s3 cp deployment_package.zip s3://${{ secrets.BUCKET_NAME }}/$GITHUB_SHA.zip | |
- name: Create deployment to AWS CodeDeploy | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ secrets.CODEDEPLOY_APP_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_NAME }} \ | |
--s3-location bucket=${{ secrets.BUCKET_NAME }},key=$GITHUB_SHA.zip,bundleType=zip \ | |
--file-exists-behavior OVERWRITE |