remove target revision #6
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: Ratings Service Build, Push and Deploy | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- 'bookinfo_app/src/ratings/**' | |
env: | |
ECR_REGISTRY: 152175719540.dkr.ecr.eu-west-1.amazonaws.com | |
ECR_REPOSITORY: book-ecr-repo | |
jobs: | |
build_and_push_image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- 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: eu-west-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Get short SHA | |
id: get-sha | |
run: echo "::set-output name=sha::$(git rev-parse --short HEAD)" | |
- name: Build and push Docker image | |
env: | |
ECR_REGISTRY: ${{ env.ECR_REGISTRY }} | |
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }} | |
IMAGE_TAG: ratings-${{ steps.get-sha.outputs.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./bookinfo_app/src/ratings/ | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
- name: Update Kubernetes Deployment Image | |
env: | |
ECR_REGISTRY: ${{ env.ECR_REGISTRY }} | |
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }} | |
IMAGE_TAG: ratings-${{ steps.get-sha.outputs.sha }} | |
run: | | |
DEPLOYMENT_FILE="manifests/kubernetes/ratings/deployment_ratings.yaml" | |
# Check if the deployment file needs update | |
if grep -q "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" "$DEPLOYMENT_FILE"; then | |
echo "Image already up to date in $DEPLOYMENT_FILE" | |
else | |
# Update the image in the deployment file | |
sed -i "s|image: 152175719540.dkr.ecr.eu-west-1.amazonaws.com/book-ecr-repo:.*|image: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG|" "$DEPLOYMENT_FILE" | |
# Show the updated deployment file | |
cat "$DEPLOYMENT_FILE" | |
# Commit and push changes | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add "$DEPLOYMENT_FILE" | |
git commit -m "Update deployment image to $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
git push | |
fi | |