Skip to content

Change place where we are configurating aws variables #29

Change place where we are configurating aws variables

Change place where we are configurating aws variables #29

Workflow file for this run

name: Deploy backend
on:
push:
branches:
- main
paths:
- "server/**"
- ".github/workflows/backdeploy.yaml"
env:
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}

Check failure on line 12 in .github/workflows/backdeploy.yaml

View workflow run for this annotation

GitHub Actions / Deploy backend

Invalid workflow file

The workflow is not valid. .github/workflows/backdeploy.yaml (Line: 12, Col: 23): Unrecognized named-value: 'env'. Located at position 1 within expression: env.AWS_DEFAULT_REGION
AWS_ACCESS_KEY_ID: ${{ secrets.CI_CD_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_CD_AWS_SECRET_ACCESS_KEY }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Restore gradle dependencies
uses: actions/cache@v2
with:
path: "~/.gradle"
key: ${{ runner.os }}-modules-${{ hashFiles('**/server/build.gradle') }}
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Add version info
run: |
export GIT_HASH=$(git rev-parse --short HEAD)
sed -i "s|version: 1.0.0|version: ${GIT_HASH}|g" server/src/main/resources/application.yaml
- name: Build jar
run: ./server/gradlew build -p server -x test
- name: Restore application.yaml
run: git checkout server/src/main/resources/application.yaml
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push to ECR
run: |
cd server
./gradlew clean build --info -x test
export STAGE=prod
GIT_HASH=$(git rev-parse --short HEAD)
# Get value from ssm and export it
ECR_URL_PARAM=$(aws ssm get-parameter --name "/$STAGE/ecr/url/statistics_server")
ECR_URL=$(echo $ECR_URL_PARAM | jq -r '.Parameter.Value')
# Before and after the bar
ECR_URL_ROOT="${ECR_URL%%/*}"
ECR_URL_SPEC="${ECR_URL##*/}"
aws ecr get-login-password --region ${{ env.AWS_DEFAULT_REGION }} | docker login --username AWS --password-stdin $ECR_URL_ROOT
docker build -t $ECR_URL_SPEC .
docker tag $ECR_URL_SPEC:latest $ECR_URL:latest
docker tag $ECR_URL_SPEC:latest $ECR_URL:$GIT_HASH
docker push $ECR_URL:latest
docker push $ECR_URL:$GIT_HASH
- name: Blue green deployment
run: |
aws deploy create-deployment \
--application-name ${{ secrets.APPLICATION_NAME }} \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP }} \
--s3-location ${{ secrets.S3_LOCATION }}