feat: Added multi-platform support #3
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 Image | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Ensure all tags are fetched | |
# Fetch the latest Git tag | |
- name: Get latest Git tag | |
id: git-tag | |
run: | | |
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
echo "TAG=$TAG" >> $GITHUB_ENV | |
# Get the Git short SHA | |
- name: Get Git short SHA | |
id: git-sha | |
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
# Increment the patch version and prepare the new tag | |
- name: Increment version | |
id: increment-version | |
run: | | |
OLD_TAG=${{ env.TAG }} | |
NEW_TAG=$(echo $OLD_TAG | awk -F. -v OFS=. '{$3+=1; print}') | |
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
echo "NEW_TAG_SHORT=$NEW_TAG-${{ env.SHORT_SHA }}" >> $GITHUB_ENV | |
# Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# Log in to Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
# Build and push the Docker image | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: openaictl | |
file: openaictl/Dockerfile | |
platforms: linux/arm/v7,linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
gshiva/openaictl:latest | |
gshiva/openaictl:${{ env.NEW_TAG }} | |
gshiva/openaictl:${{ env.NEW_TAG_SHORT }} | |
# Create and push the new Git tag | |
- name: Create and push Git tag | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git tag -a ${{ env.NEW_TAG }} -m "Release ${{ env.NEW_TAG }}" | |
git push origin ${{ env.NEW_TAG }} |