Last active
November 24, 2025 10:01
-
-
Save cdbkr/cb52173d4a842e147742a91d416f3da4 to your computer and use it in GitHub Desktop.
.github/workflows/ci.yaml
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 artifacts and deploy to the Infrastructure Repo Stack | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| build: | |
| name: Build Image | |
| runs-on: ubuntu-latest | |
| outputs: | |
| built-image-version: ${{ steps.git-tag.outputs.new_tag }} | |
| ecr-registry: ${{ steps.login-ecr.outputs.registry }} | |
| steps: | |
| - name: Check out 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 }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
| aws-default-region: eu-central-1 | |
| aws-region: eu-central-1 | |
| - name: Check out code | |
| uses: actions/checkout@v2 | |
| - name: Bump version and push tag | |
| id: git-tag | |
| uses: anothrNick/[email protected] | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB_ACTIONS }} | |
| WITH_V: false | |
| INITIAL_VERSION: 1.1.0 | |
| DEFAULT_BUMP: patch | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Build, tag, and push image to Amazon ECR | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: my-organization/simple-api | |
| IMAGE_TAG: ${{ steps.git-tag.outputs.new_tag }} | |
| run: | | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| deploy: | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout prod repo | |
| uses: actions/checkout@v2 | |
| with: | |
| repository: my-organization/prod-env | |
| token: ${{ secrets.TOKEN_GITHUB_ACTIONS }} | |
| - name: Update kustomize image and push change | |
| env: | |
| IMAGE_NAME: simple-api | |
| IMAGE_REPO: ${{ needs.build.outputs.ecr-registry }}/my-organization/simple-api | |
| VERSION: ${{ needs.build.outputs.built-image-version }} | |
| run: | | |
| # Move into the directory to update | |
| cd apps/simple-api/prod | |
| # Update the kustomize image with the newly built one | |
| kustomize edit set image "${IMAGE_NAME}=${IMAGE_REPO}:${VERSION}" | |
| # Return to repo root | |
| cd - | |
| # Commit & push changes | |
| git config user.name "My-Organization Actions" | |
| git config user.email "actions@my-organization" | |
| git add apps/simple-api/prod | |
| if git commit -m "chore: bump ${IMAGE_NAME} to version ${VERSION}"; then | |
| git push origin main | |
| else | |
| echo "No changes to commit" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment