Build and Push Docker Images #1
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: Build and Push Docker Images | |
# reusable workflow, do not add triggers | |
on: | |
workflow_call: | |
workflow_dispatch: | |
env: | |
GHCR: ghcr.io/${{ github.repository }} | |
PLATFORMS: linux/amd64 | |
jobs: | |
build-docker: | |
name: Build Docker Images | |
runs-on: ubuntu-latest | |
environment: CI | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: us-east-1 | |
role-to-assume: ${{ secrets.AWS_OIDC_ROLE }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
fetch-tags: true | |
ref: ${{ github.ref }} | |
- name: Set up docker buildx for push | |
uses: docker/setup-buildx-action@v3 | |
- name: Metadata for xion container | |
id: meta-xion | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
burntnetwork/xion | |
${{ env.GHCR }}/xion | |
385156030167.dkr.ecr.us-east-1.amazonaws.com/burnt/xiond | |
tags: | | |
type=sha | |
type=semver,pattern={{version}},enable=${{ github.event_name == 'push' }} | |
type=raw,value=latest,enable={{is_default_branch}} | |
- name: Prepare xion build environment | |
run: | | |
echo "VERSION=$(shell echo $(shell git describe --tags) | sed 's/^v//')" >> $GITHUB_ENV | |
echo "COMMIT=$(shell git log -1 --format='%H')" >> $GITHUB_ENV | |
echo "TAG_VERSION=$(shell git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- name: Build and push xion image | |
uses: docker/build-push-action@v5 | |
env: | |
COMMIT: ${{ env.COMMIT }} | |
VERSION: ${{ env.VERSION }} | |
TAG_VERSION: ${{ env.TAG_VERSION }} | |
with: | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
target: release | |
platforms: ${{ env.PLATFORMS }} | |
tags: ${{ steps.meta-xion.outputs.tags }} | |
labels: ${{ steps.meta-xion.outputs.labels }} |