feat: Build agent on CI/CD #26
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: Docker Image CI | |
on: | |
push: | |
branches: ["master"] | |
env: | |
GHCR_REPO: ghcr.io/thegamerx1/wakeonlan | |
jobs: | |
build-docker: | |
strategy: | |
matrix: | |
cpu: [arm64, amd64] | |
include: | |
- cpu: arm64 | |
runner: ARM64 | |
tag: arm64 | |
- cpu: amd64 | |
runner: X64 | |
tag: amd64 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} # Automatically uses GitHub token for auth | |
- name: Build and Push Docker Image for arm | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile.arm | |
provenance: false | |
platforms: linux/${{ matrix.cpu }} | |
push: true # Automatically push after build | |
tags: "${{ env.GHCR_REPO }}:${{ github.sha }}-${{ matrix.tag }}" | |
docker-manifest: | |
runs-on: ubuntu-latest | |
needs: [build-docker] | |
steps: | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.GHCR_REPO }} | |
flavor: ${{ inputs.flavor }} | |
tags: ${{ inputs.tags }} | |
- name: Login to GitHub container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create and push manifests | |
run: | | |
tags='${{ env.GHCR_REPO }}:${{ github.sha }} ${{ steps.meta.outputs.tags }}' | |
for tag in ${tags} | |
do | |
docker manifest rm ${tag} || true | |
docker manifest create ${tag} ${{ env.GHCR_REPO }}:${{ github.sha }}-amd64 ${{ env.GHCR_REPO }}:${{ github.sha }}-arm64 | |
docker manifest push ${tag} | |
done | |
build-agent: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] # Define Linux and Windows OS | |
architecture: [amd64, arm64] # Specify architectures for Linux only (not Windows) | |
exclude: | |
- os: windows-latest | |
architecture: arm64 # Exclude arm64 for Windows, as you want only amd64 for Windows | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
rustflags: "" | |
toolchain: "stable" | |
- name: Build | |
run: | | |
cargo build --release -p agent | |
- name: Prep release | |
shell: bash | |
run: | | |
EXE_suffix="" | |
case ${{ matrix.os }} in | |
*windows*) EXE_suffix=".exe" ;; | |
esac; | |
mkdir release | |
mv target/release/agent${EXE_suffix} release/agent-${{ matrix.os }}-${{ matrix.architecture }}${EXE_suffix} | |
- name: Check for release | |
id: is-release | |
shell: bash | |
run: | | |
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi | |
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT | |
- name: Publish archives and packages | |
uses: softprops/action-gh-release@v2 | |
if: steps.is-release.outputs.IS_RELEASE | |
with: | |
files: | | |
release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Upload release binary as artifact | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: agent-${{ matrix.os }}-${{ matrix.architecture }} | |
# path: release/* | |
# if-no-files-found: error | |
# build-docker: | |
# runs-on: windows-latest | |
# - name: Build the Docker image for amd64 | |
# run: docker buildx build -t wakeonlan:latest-amd64 --platform linux/amd64 . | |
# - name: Build the Docker image for arm64 | |
# run: docker buildx build -t wakeonlan:latest-arm64 --platform linux/arm64/v8 -f Dockerfile.arm . |