Increment version to 0.0.2 #28
This file contains hidden or 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 | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - 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: eu-west-2 | |
| - name: Login to Amazon ECR | |
| id: ecr-login | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Build Docker image | |
| run: docker build -t asyncdb:latest . | |
| - name: Read version | |
| id: get_version | |
| run: | | |
| VERSION=$(cat version) | |
| echo "Version: $VERSION" | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Check if version exists in ECR | |
| id: check_version | |
| run: | | |
| if aws ecr describe-images \ | |
| --repository-name asyncdb \ | |
| --image-ids imageTag=$VERSION \ | |
| --region eu-west-2 \ | |
| --query 'imageDetails[0].imageTags[0]' | |
| then | |
| echo "Image version $VERSION already exists in ECR." | |
| echo "publish=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Publishing..." | |
| echo "publish=true" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_DEFAULT_REGION: eu-west-2 | |
| VERSION: ${{ env.VERSION }} | |
| - name: Tag Docker image for ECR | |
| if: steps.check_version.outputs.publish == 'true' | |
| run: | | |
| IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION | |
| docker tag asyncdb:latest $IMAGE_URI | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| - name: Push Docker image to ECR | |
| if: steps.check_version.outputs.publish == 'true' | |
| run: | | |
| IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION | |
| docker push $IMAGE_URI | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| - name: Tag Git repo with version | |
| if: steps.check_version.outputs.publish == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "$VERSION" | |
| git push origin "$VERSION" | |
| env: | |
| VERSION: ${{ env.VERSION }} | |