Build and Push Docker Image #58
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: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
inputs: | |
force_build: | |
description: 'Force rebuild even if no new version is found (true/false)' | |
required: false | |
default: 'false' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Check for Nezha Agent updates | |
run: | | |
LATEST_VERSION=$(curl -s https://api.github.com/repos/nezhahq/agent/releases/latest | grep tag_name | cut -d '"' -f 4) | |
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV | |
- name: Build and push | |
if: env.LATEST_VERSION != env.CURRENT_VERSION || github.event.inputs.force_build == 'true' | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
kanggle/nezha-agent:${{ env.LATEST_VERSION }} | |
kanggle/nezha-agent:latest | |
build-args: | | |
VERSION=${{ env.LATEST_VERSION }} | |
- name: Save Docker image as tar archive | |
if: env.LATEST_VERSION != env.CURRENT_VERSION || github.event.inputs.force_build == 'true' | |
run: | | |
mkdir -p release | |
docker pull kanggle/nezha-agent:${{ env.LATEST_VERSION }} --platform linux/amd64 | |
docker save kanggle/nezha-agent:${{ env.LATEST_VERSION }} -o release/nezha-agent-amd64.tar | |
docker pull kanggle/nezha-agent:${{ env.LATEST_VERSION }} --platform linux/arm64 | |
docker save kanggle/nezha-agent:${{ env.LATEST_VERSION }} -o release/nezha-agent-arm64.tar | |
- name: Compress tar archives | |
if: env.LATEST_VERSION != env.CURRENT_VERSION || github.event.inputs.force_build == 'true' | |
run: | | |
cd release | |
gzip nezha-agent-amd64.tar | |
gzip nezha-agent-arm64.tar | |
- name: Create GitHub Release | |
if: env.LATEST_VERSION != env.CURRENT_VERSION || github.event.inputs.force_build == 'true' | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ env.LATEST_VERSION }} | |
files: | | |
release/nezha-agent-amd64.tar.gz | |
release/nezha-agent-arm64.tar.gz |