feat: systemd unit for zia-client in deb package #4
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: CI | |
on: | |
push: | |
branches: [ main ] | |
tags: [ '*' ] | |
pull_request: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
target: | |
- x86_64-unknown-linux-gnu | |
- aarch64-unknown-linux-gnu | |
- armv7-unknown-linux-gnueabihf | |
- aarch64-linux-android | |
linker: [ static, dynamic ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo-${{ matrix.target }}- | |
- uses: dtolnay/rust-toolchain@nightly | |
- name: Install cross | |
run: cargo install --force cross --git https://github.com/cross-rs/cross | |
# run: wget -cO - https://github.com/cross-rs/cross/releases/latest/download/cross-x86_64-unknown-linux-gnu.tar.gz | tar -xz | |
- run: cargo install --force cargo-deb | |
if: matrix.linker == 'dynamic' | |
# - run: cargo install --force cargo-generate-rpm | |
- name: Find Version | |
if: startsWith(github.ref, 'refs/tags/') | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: image | |
tags: type=semver,pattern={{version}} | |
- name: Set Cargo.toml version | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" zia-client/Cargo.toml | |
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" zia-common/Cargo.toml | |
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" zia-server/Cargo.toml | |
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" Cargo.lock | |
- name: Configure for static | |
run: | | |
if [[ '${{ matrix.linker }}' == 'static' ]]; then | |
echo 'RUSTFLAGS=-C target-feature=+crt-static' >> $GITHUB_ENV | |
echo 'NAME_PREFIX=_static' >> $GITHUB_ENV | |
fi | |
- name: Build | |
run: cross build --release --target ${{ matrix.target }} | |
- name: Build deb | |
if: matrix.linker == 'dynamic' | |
run: | | |
cargo deb --no-build --no-strip --target ${{ matrix.target }} -p zia-client | |
cargo deb --no-build --no-strip --target ${{ matrix.target }} -p zia-server | |
# - name: Build rpm | |
# run: | | |
# cargo generate-rpm --target ${{ matrix.target }} -p zia-client | |
# cargo generate-rpm --target ${{ matrix.target }} -p zia-server | |
- name: Rename binary | |
run: | | |
mv target/${{ matrix.target }}/release/zia-client zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }} | |
mv target/${{ matrix.target }}/release/zia-server zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }} | |
- name: Upload Artifact (client) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }} | |
path: zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }} | |
- name: Upload Artifact (server) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }} | |
path: zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }} | |
- name: Upload Artifact deb (client) | |
if: matrix.linker == 'dynamic' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: zia-client_${{ matrix.target }}.deb | |
path: target/${{ matrix.target }}/debian/zia-client_*.deb | |
- name: Upload Artifact deb (server) | |
if: matrix.linker == 'dynamic' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: zia-server_${{ matrix.target }}.deb | |
path: target/${{ matrix.target }}/debian/zia-server_*.deb | |
- uses: alexellis/[email protected] | |
if: startsWith(github.ref, 'refs/tags/') | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
asset_paths: '["zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }}","zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }}","target/${{ matrix.target }}/debian/zia-client_${{ steps.meta.outputs.version }}_*.deb","target/${{ matrix.target }}/debian/zia-server_${{ steps.meta.outputs.version }}_*.deb"]' | |
build-native: | |
needs: [ build ] | |
runs-on: ${{ format('{0}-latest', matrix.os) }} | |
strategy: | |
matrix: | |
os: [ windows, macos ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo- | |
- uses: dtolnay/rust-toolchain@nightly | |
- name: Find Version | |
if: startsWith(github.ref, 'refs/tags/') | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: image | |
tags: type=semver,pattern={{version}} | |
- name: Set Cargo.toml version | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" zia-client/Cargo.toml | |
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" zia-common/Cargo.toml | |
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" zia-server/Cargo.toml | |
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" Cargo.lock | |
- name: Build | |
run: cargo build --release | |
- name: Rename binary | |
if: matrix.os != 'windows' | |
run: | | |
mv target/release/zia-client zia-client_${{ matrix.os }}_x86_64 | |
mv target/release/zia-server zia-server_${{ matrix.os }}_x86_64 | |
- name: Rename binary (win) | |
if: matrix.os == 'windows' | |
run: | | |
mv target/release/zia-client.exe zia-client_${{ matrix.os }}_x86_64.exe | |
mv target/release/zia-server.exe zia-server_${{ matrix.os }}_x86_64.exe | |
- name: Upload Artifact (client) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: zia-client_${{ matrix.os }}_x86_64 | |
path: zia-client_${{ matrix.os }}_x86_64* | |
- name: Upload Artifact (server) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: zia-server_${{ matrix.os }}_x86_64 | |
path: zia-server_${{ matrix.os }}_x86_64* | |
- uses: alexellis/[email protected] | |
if: startsWith(github.ref, 'refs/tags/') | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
asset_paths: '["zia-client_${{ matrix.os }}_x86_64*","zia-server_${{ matrix.os }}_x86_64*"]' | |
build-docker: | |
needs: [ build ] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
component: [ client, server ] | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
- name: Organize binaries | |
run: | | |
mkdir -p ctx/linux/amd64 ctx/linux/arm64 ctx/linux/arm/v7 | |
mv zia-${{ matrix.component }}_x86_64-unknown-linux-gnu/zia-${{ matrix.component }}_x86_64-unknown-linux-gnu ctx/linux/amd64/zia-${{ matrix.component }} | |
mv zia-${{ matrix.component }}_aarch64-unknown-linux-gnu/zia-${{ matrix.component }}_aarch64-unknown-linux-gnu ctx/linux/arm64/zia-${{ matrix.component }} | |
mv zia-${{ matrix.component }}_armv7-unknown-linux-gnueabihf/zia-${{ matrix.component }}_armv7-unknown-linux-gnueabihf ctx/linux/arm/v7/zia-${{ matrix.component }} | |
chmod +x ctx/linux/amd64/zia-${{ matrix.component }} | |
chmod +x ctx/linux/arm64/zia-${{ matrix.component }} | |
chmod +x ctx/linux/arm/v7/zia-${{ matrix.component }} | |
tree ctx | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository_owner }}/zia-${{ matrix.component }} | |
tags: | | |
type=edge | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-${{ matrix.component }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.component }}-buildx- | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Build | |
uses: docker/build-push-action@v5 | |
with: | |
file: Dockerfile.gh-actions | |
context: ctx | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
build-args: COMPONENT=${{ matrix.component }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |