build rpm packages #106
Workflow file for this run
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 Release | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
jobs: | ||
create_release: | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set Env | ||
run: | | ||
VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//') | ||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV | ||
- name: Create GitHub Release | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
if gh release view $RELEASE_TAG &>/dev/null; then | ||
echo "Release $RELEASE_TAG exists. skipping" | ||
else | ||
echo "Release $RELEASE_TAG does not exists. creating..." | ||
RELEASE_NOTES=$(sed -e "/^## ${RELEASE_TAG}/,/^## / ! d" CHANGELOG.md | tail -n +2 | head -n -1) | ||
if [[ ${{ contains(github.ref_name, '-rc') }} == 'true' || ${{ contains(github.ref_name, '-beta') }} == 'true' || ${{ contains(github.ref_name, '-alpha') }} == 'true' ]]; then | ||
gh release create $RELEASE_TAG \ | ||
--generate-notes \ | ||
--title $RELEASE_TAG \ | ||
--notes "$RELEASE_NOTES" \ | ||
--prerelease | ||
else | ||
gh release create $RELEASE_TAG \ | ||
--generate-notes \ | ||
--title $RELEASE_TAG \ | ||
--notes "$RELEASE_NOTES" | ||
fi | ||
fi | ||
create_static: | ||
permissions: | ||
contents: write | ||
runs-on: "${{ matrix.os }}" | ||
needs: create_release | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-latest-4-cores-arm64 | ||
target: arm64 | ||
- os: ubuntu-latest | ||
target: amd64 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set Env | ||
run: | | ||
VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//') | ||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV | ||
- name: Build release artifacts | ||
run: | | ||
docker build --platform linux/${{ matrix.target }} --output type=local,dest=docker_output/ -f release/Containerfile-build-static . | ||
- name: Upload Release Asset | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
mv ./docker_output/peridiod-${RELEASE_VERSION}.tar.gz ./docker_output/peridiod-${RELEASE_VERSION}-${{ matrix.target }}-static.tar.gz | ||
gh release upload $RELEASE_TAG ./docker_output/peridiod-${RELEASE_VERSION}-${{ matrix.target }}-static.tar.gz --clobber | ||
create_container_images: | ||
permissions: | ||
contents: write | ||
runs-on: "${{ matrix.os }}" | ||
needs: create_release | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-latest-4-cores-arm64 | ||
target: arm64 | ||
- os: ubuntu-latest | ||
target: amd64 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set Env | ||
run: | | ||
VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//') | ||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV | ||
- name: Load docker hub credentials | ||
id: op-load-docker-hub-credentials | ||
uses: 1password/load-secrets-action@v1 | ||
with: | ||
export-env: false | ||
env: | ||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | ||
DOCKER_HUB_USERNAME: op://ci-cd/docker-hub-machine/username | ||
DOCKER_HUB_PASSWORD: op://ci-cd/docker-hub-machine/password | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_USERNAME }} | ||
password: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_PASSWORD }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./release/Containerfile-release | ||
push: true | ||
tags: | | ||
peridio/peridiod:${{ env.RELEASE_TAG }}-${{ matrix.target }} | ||
create_container_manifest: | ||
runs-on: ubuntu-latest | ||
needs: create_container_images | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set Env | ||
run: | | ||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Load docker hub credentials | ||
id: op-load-docker-hub-credentials | ||
uses: 1password/load-secrets-action@v1 | ||
with: | ||
export-env: false | ||
env: | ||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | ||
DOCKER_HUB_USERNAME: op://ci-cd/docker-hub-machine/username | ||
DOCKER_HUB_PASSWORD: op://ci-cd/docker-hub-machine/password | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_USERNAME }} | ||
password: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_PASSWORD }} | ||
- name: Create and Push Manifest | ||
run: | | ||
docker manifest create peridio/peridiod:${{ env.RELEASE_TAG }} \ | ||
--amend peridio/peridiod:${{ env.RELEASE_TAG }}-arm64 \ | ||
--amend peridio/peridiod:${{ env.RELEASE_TAG }}-amd64 | ||
docker manifest push peridio/peridiod:${{ env.RELEASE_TAG }} | ||
if [[ "${{ env.RELEASE_TAG }}" != *-* ]]; then | ||
docker manifest create peridio/peridiod:latest \ | ||
--amend peridio/peridiod:${{ env.RELEASE_TAG }}-arm64 \ | ||
--amend peridio/peridiod:${{ env.RELEASE_TAG }}-amd64 | ||
docker manifest push peridio/peridiod:latest | ||
else | ||
echo "Skipping latest tag update for pre-release tag ${{ env.RELEASE_TAG }}" | ||
fi | ||
create_debs: | ||
runs-on: "${{ matrix.os }}" | ||
needs: create_release | ||
permissions: | ||
contents: write | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-latest-4-cores-arm64 | ||
target: arm64 | ||
distro: jammy | ||
- os: ubuntu-latest-4-cores-arm64 | ||
target: arm64 | ||
distro: noble | ||
- os: ubuntu-latest | ||
target: amd64 | ||
target: jammy | ||
- os: ubuntu-latest | ||
target: amd64 | ||
target: noble | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set Env | ||
run: | | ||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Cache Debian packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/deb | ||
key: ${{ runner.os }}-deb-cache | ||
restore-keys: | | ||
${{ runner.os }}-deb-cache | ||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y dpkg-dev debhelper fakeroot | ||
- name: Build release artifacts | ||
run: | | ||
docker build --platform linux/${{ matrix.target }} --output type=local,dest=docker_output/ -f release/Containerfile-build-${{ matrix.distro }} . | ||
- name: Build DEB package | ||
run: | | ||
source release/package-info.sh | ||
PERIDIOD_ARCH=${{ matrix.target }} | ||
PERIDIOD_VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//') | ||
PERIDIOD_PACKAGE_DIR=$(pwd)/package/peridiod_${PERIDIOD_VERSION}_${PERIDIOD_ARCH} | ||
PERIDIOD_RELEASE_NOTES=$(sed -e "/^## ${RELEASE_TAG}/,/^## / ! d" CHANGELOG.md | tail -n +2 | head -n -1) | ||
export PERIDIOD_RELEASE_NOTES | ||
export PERIDIOD_VERSION | ||
export PERIDIOD_ARCH | ||
release/build-deb.sh ./docker_output/peridiod-${PERIDIOD_VERSION}.tar.gz $PERIDIOD_PACKAGE_DIR | ||
mv "${PERIDIOD_PACKAGE_DIR}.deb" ./peridiod_${PERIDIOD_VERSION}_${PERIDIOD_ARCH}.${{ matrix.distro }}.deb | ||
echo "PERIDIOD_PACKAGE=peridiod_${PERIDIOD_VERSION}_${PERIDIOD_ARCH}.${{ matrix.distro }}.deb" >> $GITHUB_ENV | ||
- name: Upload Release Asset | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh release upload $RELEASE_TAG $PERIDIOD_PACKAGE --clobber | ||
create_rpms: | ||
runs-on: "${{ matrix.os }}" | ||
needs: create_release | ||
permissions: | ||
contents: write | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-latest-4-cores-arm64 | ||
target: arm64 | ||
distro: rhel9 | ||
- os: ubuntu-latest | ||
target: amd64 | ||
distro: rhel9 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set Env | ||
run: | | ||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y dpkg-dev debhelper fakeroot | ||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y dpkg-dev debhelper fakeroot | ||
- name: Build release artifacts | ||
run: | | ||
docker build --platform linux/${{ matrix.target }} --output type=local,dest=docker_output/ -f release/Containerfile-build-${{ matrix.distro }} . | ||
- name: Build RPM package | ||
run: | | ||
source release/package-info.sh | ||
PERIDIOD_ARCH=${{ matrix.target }} | ||
if [ "$PERIDIOD_ARCH" == "arm64" ]; then | ||
PERIDIOD_ARCH_RPM="aarch64" | ||
elif [ "$PERIDIOD_ARCH" == "amd64" ]; then | ||
PERIDIOD_ARCH_RPM="x86_64" | ||
else | ||
PERIDIOD_ARCH_RPM="$ARCH" | ||
fi | ||
PERIDIOD_VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//') | ||
PERIDIOD_VERSION_RPM=${PERIDIOD_VERSION//-/_} | ||
PERIDIOD_PACKAGE_DIR=$(pwd)/package/peridiod_${PERIDIOD_VERSION}_${PERIDIOD_ARCH} | ||
PERIDIOD_RELEASE_NOTES=$(sed -e "/^## ${RELEASE_TAG}/,/^## / ! d" CHANGELOG.md | tail -n +2 | head -n -1) | ||
export PERIDIOD_RELEASE_NOTES | ||
export PERIDIOD_VERSION | ||
export PERIDIOD_VERSION_RPM | ||
export PERIDIOD_ARCH | ||
export PERIDIOD_ARCH_RPM | ||
release/build-rpm.sh ./docker_output/peridiod-${PERIDIOD_VERSION}.tar.gz $PERIDIOD_PACKAGE_DIR | ||
mv "${PERIDIOD_PACKAGE_DIR}/RPMS/$PERIDIOD_ARCH_RPM/peridiod-${PERIDIOD_VERSION_RPM}-1.${PERIDIOD_ARCH_RPM}.rpm" peridiod-${PERIDIOD_VERSION_RPM}-1.${PERIDIOD_ARCH_RPM}.${{ matrix.distro }}.rpm | ||
echo "PERIDIOD_PACKAGE=peridiod-${PERIDIOD_VERSION_RPM}-1.${PERIDIOD_ARCH_RPM}.${{ matrix.distro }}.rpm" >> $GITHUB_ENV | ||
- name: Upload Release Asset | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh release upload $RELEASE_TAG $PERIDIOD_PACKAGE --clobber |