fix(auth): test cicd #13
Workflow file for this run
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: Build and Push Docker Image to ECR | ||
on: | ||
push: | ||
branches: | ||
# - main | ||
# - develop | ||
- feat/cicd | ||
jobs: | ||
build: | ||
name: Build Docker Image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
- name: Build JAR | ||
run: ./gradlew build -x test | ||
- name: Determine ECR Repository | ||
id: ecr_repo | ||
run: | | ||
REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') | ||
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then | ||
echo "repo=${REPO_NAME}_prod" >> $GITHUB_OUTPUT | ||
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/feat/cicd" ]]; then | ||
echo "repo=${REPO_NAME}_stag" >> $GITHUB_OUTPUT | ||
else | ||
echo "::error::Unsupported event or branch: ${{ github.event_name }} on ${{ github.ref }}" | ||
exit 1 | ||
fi | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
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@v2 | ||
- name: Docker Build and Push | ||
run: | | ||
docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}:${{ github.sha }} . | ||
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}:${{ github.sha }} | ||
- name: Checkout Private Repository | ||
uses: actions/checkout@v4 | ||
repository: NTF-marketplace/devops | ||
fetch-depth: 0 | ||
ref: develop | ||
token: ${{ secrets.PAT }} | ||
- name: Replace image tag in helm values (LOCAL) | ||
uses: mikefarah/yq@master | ||
env: | ||
IMAGE_TAG: ${{ github.sha }} | ||
with: | ||
cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/auth_stag/values.yaml' | ||
- name: Commit helm chart changes | ||
env: | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
cd chart | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "dongdorrong" | ||
git add values.yaml | ||
git commit --message "ci: update auth_stag image tag to $IMAGE_TAG" | ||
- name: Push commit | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.PAT }} | ||
repository: NTF-marketplace/devops |