mirror of
https://github.com/cyclotruc/gitingest.git
synced 2026-04-28 11:41:35 +00:00
Some checks failed
CI / test (macos-latest, 3.13) (push) Has been cancelled
CI / test (macos-latest, 3.8) (push) Has been cancelled
CI / test (true, ubuntu-latest, 3.13) (push) Has been cancelled
CI / test (ubuntu-latest, 3.8) (push) Has been cancelled
CI / test (windows-latest, 3.13) (push) Has been cancelled
CI / test (windows-latest, 3.8) (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Build & Push Container / ECR (push) Has been cancelled
Build & Push Container / GHCR (push) Has been cancelled
release-please / release (push) Has been cancelled
OSSF Scorecard / Scorecard analysis (push) Has been cancelled
114 lines
4.1 KiB
YAML
114 lines
4.1 KiB
YAML
name: Build & Push Container
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
tags:
|
|
- '*'
|
|
merge_group:
|
|
pull_request:
|
|
types: [labeled, synchronize, reopened, ready_for_review, opened]
|
|
|
|
env:
|
|
PUSH_FROM_PR: >-
|
|
${{ github.event_name == 'pull_request' &&
|
|
(
|
|
contains(github.event.pull_request.labels.*.name, 'push-container') ||
|
|
contains(github.event.pull_request.labels.*.name, 'deploy-pr-temp-env')
|
|
)
|
|
}}
|
|
|
|
jobs:
|
|
terraform:
|
|
name: "ECR"
|
|
runs-on: ubuntu-latest
|
|
if: github.repository == 'coderamp-labs/gitingest'
|
|
|
|
permissions:
|
|
id-token: write
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
with:
|
|
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
|
|
|
|
- name: configure aws credentials
|
|
uses: aws-actions/configure-aws-credentials@v4
|
|
with:
|
|
role-to-assume: ${{ secrets.CODERAMP_AWS_ECR_REGISTRY_PUSH_ROLE_ARN }}
|
|
role-session-name: GitHub_to_AWS_via_FederatedOIDC
|
|
aws-region: eu-west-1
|
|
|
|
- name: Set current timestamp
|
|
id: vars
|
|
run: |
|
|
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
|
|
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Determine version and deployment context
|
|
id: version
|
|
run: |
|
|
REPO_URL="https://github.com/${{ github.repository }}"
|
|
|
|
if [[ "${{ github.ref_type }}" == "tag" ]]; then
|
|
# Tag deployment - display version, link to release
|
|
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
|
|
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
|
|
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
# PR deployment - display pr-XXX, link to PR commit
|
|
PR_NUMBER="${{ github.event.pull_request.number }}"
|
|
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
|
|
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
|
|
echo "app_version=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
|
|
echo "app_version_url=${REPO_URL}/pull/${PR_NUMBER}/commits/${COMMIT_HASH}" >> $GITHUB_OUTPUT
|
|
else
|
|
# Branch deployment - display branch name, link to commit
|
|
BRANCH_NAME="${{ github.ref_name }}"
|
|
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
|
|
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
|
|
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Login to Amazon ECR
|
|
id: login-ecr
|
|
uses: aws-actions/amazon-ecr-login@v2
|
|
|
|
- name: Docker Meta
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ secrets.ECR_REGISTRY_URL }}
|
|
flavor: |
|
|
latest=false
|
|
tags: |
|
|
type=ref,event=branch,branch=main,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }}
|
|
type=ref,event=pr,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }}
|
|
type=pep440,pattern={{raw}}
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64, linux/arm64
|
|
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
APP_REPOSITORY=https://github.com/${{ github.repository }}
|
|
APP_VERSION=${{ steps.version.outputs.app_version }}
|
|
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|