Skip to content

Instantly share code, notes, and snippets.

@ch-hristov
Created January 5, 2026 17:17
Show Gist options
  • Select an option

  • Save ch-hristov/0f14eff403e1e541e859cac2ffe7de23 to your computer and use it in GitHub Desktop.

Select an option

Save ch-hristov/0f14eff403e1e541e859cac2ffe7de23 to your computer and use it in GitHub Desktop.
name: CI/CD Pipeline
on:
push:
branches: [develop, main]
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GitHubActionsRole
role-session-name: GitHubActions
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set image tag
id: set_tag
run: |
if [[ "${GITHUB_REF##*/}" == "main" ]]; then
echo "TAG=prod" >> $GITHUB_ENV
elif [[ "${GITHUB_REF##*/}" == "develop" ]]; then
echo "TAG=dev" >> $GITHUB_ENV
else
echo "TAG=${GITHUB_SHA}" >> $GITHUB_ENV
fi
- name: Build and push Docker image
run: |
docker build -t ${{ github.event.repository.name }}:${{ github.sha }} .
docker tag ${{ github.event.repository.name }}:${{ github.sha }} ${{ steps.login-ecr.outputs.registry }}/${{ github.event.repository.name }}:${{ github.sha }}
docker tag ${{ github.event.repository.name }}:${{ github.sha }} ${{ steps.login-ecr.outputs.registry }}/${{ github.event.repository.name }}:${{ env.TAG }}-latest
docker push ${{ steps.login-ecr.outputs.registry }}/${{ github.event.repository.name }}:${{ github.sha }}
docker push ${{ steps.login-ecr.outputs.registry }}/${{ github.event.repository.name }}:${{ env.TAG }}-latest
# - name: Deploy to Production
# if: github.ref == 'refs/heads/main'
# run: |
# # Trigger infrastructure deployment with new image tag
# curl -X POST \
# -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github.v3+json" \
# https://api.github.com/repos/test/test/dispatches \
# -d '{
# "event_type": "deploy-prod",
# "client_payload": {
# "image_tag": "${{ github.sha }}",
# "environment": "prod"
# }
# }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment