Skip to content

Commit

Permalink
RPM build
Browse files Browse the repository at this point in the history
  • Loading branch information
alpinskiy committed Mar 4, 2024
1 parent 6fdaa71 commit 551ea75
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 104 deletions.
52 changes: 26 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,33 @@ jobs:
- run: make build-sh-ui
- uses: actions/upload-artifact@v4
with:
name: statshouse-${{needs.env.outputs.version}}-ui
name: statshouse-ui-${{needs.env.outputs.version}}
path: |
statshouse-ui/build
cmd/statshouse-api/build
.dummy_preserves_directory_structure
outputs:
artifact: statshouse-${{needs.env.outputs.version}}-ui
almalinux:
artifact: statshouse-ui-${{needs.env.outputs.version}}
rpm:
strategy:
matrix:
image: ["centos:centos7", "almalinux:9"]
needs: [env, frontend]
uses: ./.github/workflows/build_rpm.yml
with:
ref: ${{needs.env.outputs.ref}}
ref_timestamp: ${{needs.env.outputs.ref_timestamp}}
timestamp: ${{needs.env.outputs.timestamp}}
version: ${{needs.env.outputs.version}}
name: almalinux
release: 9.2
frontend-artifact: ${{needs.frontend.outputs.artifact}}
secrets: inherit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: VKCOM/statshouse
ref: ${{needs.env.outputs.ref}}
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: ${{needs.frontend.outputs.artifact}}
- run: echo "BUILD_VERSION=`echo ${{needs.env.outputs.version}} | sed -e 's:-:.:g'`" >> $GITHUB_ENV
- run: build/makerpm.sh ${{matrix.image}}
- uses: actions/upload-artifact@v4
with:
name: statshouse-pkg-rpm-${{needs.env.outputs.version}}${{strategy.job-index}}
path: RPMS/*.rpm
debian:
if: ${{false}}
strategy:
Expand Down Expand Up @@ -114,7 +123,7 @@ jobs:
secrets: inherit
draft_release:
if: ${{ github.event.inputs.draft_release }}
needs: [env, ubuntu_focal, almalinux]
needs: [env, rpm, ubuntu_focal]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -124,17 +133,8 @@ jobs:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: ${{needs.almalinux.outputs.artifact}}
path: pkg/rpm
- uses: actions/download-artifact@v4
if: ${{false}}
with:
name: ${{needs.debian.outputs.artifact}}
path: pkg/deb
- uses: actions/download-artifact@v4
with:
name: ${{needs.ubuntu_focal.outputs.artifact}}
path: pkg/deb
pattern: statshouse-pkg-*
path: pkg/
- run: gh release create --draft --generate-notes --title "${{github.event.inputs.tag}}" ${{github.event.inputs.tag}} $(find ./pkg -type f -name *.deb -o -name *.rpm)
env:
GITHUB_TOKEN: ${{secrets.DEVTOOLS_GITHUB_TOKEN}}
9 changes: 3 additions & 6 deletions .github/workflows/build_deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ on:
frontend-artifact:
type: string
required: true
outputs:
artifact:
value: statshouse-${{inputs.version}}-deb
jobs:
binaries:
uses: ./.github/workflows/build_binaries.yml
Expand Down Expand Up @@ -83,8 +80,8 @@ jobs:
debuild --no-lintian -us -uc -b
- uses: actions/upload-artifact@v4
with:
name: statshouse-${{inputs.version}}-deb
name: statshouse-pkg-deb-${{inputs.version}}${{github.run_number}}${{strategy.job-index}}
path: |
./statshouse_*.deb
# ./statshouse-api_*.deb
# ./statshouse-metadata_*.deb
./statshouse-api_*.deb
./statshouse-metadata_*.deb
69 changes: 0 additions & 69 deletions .github/workflows/build_rpm.yml

This file was deleted.

2 changes: 1 addition & 1 deletion build/debian/statshouse-api.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
../target/statshouse-api usr/bin/
../cmd/statshouse-api/statshouse-api.service usr/lib/systemd/system/
../statshouse-ui/build usr/lib/statshouse-api/statshouse-ui/
../cmd/statshouse-api/build usr/lib/statshouse-api/statshouse-ui/
86 changes: 86 additions & 0 deletions build/makerpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
set -e

while (( "$#" )); do

IMAGE=$1
IMAGE_NAME=${IMAGE%:*}
IMAGE_TAG=${IMAGE#*:}

case "$IMAGE_NAME" in
"almalinux") NAME_RELEASE="almalinux$IMAGE_TAG"; DNF=dnf ;;
"centos") NAME_RELEASE=$IMAGE_TAG; DNF=yum ;;
*) echo "Target name \"$IMAGE_NAME\" is not recognized!"; shift; continue ;;
esac

NAME_RELEASE=$(echo $NAME_RELEASE | sed -e 's/-/./g;s/:/./g')

if [[ -z $GOLANG_VERSION ]]; then
echo 'Go version is not specified, using 1.22'
GOLANG_VERSION='1.22.0'
fi

# version
UPSTREAM=$(git describe --tags --always --dirty)
UPSTREAM=${UPSTREAM#v} # v1.0.0 -> 1.0.0
BUILD_TIME=$(date +%FT%T%z)
REACT_APP_BUILD_VERSION=$UPSTREAM-$BUILD_TIME
if [[ -z $BUILD_VERSION ]]; then
if [[ ! -z $BUILD_VERSION_SUFFIX ]]; then
BUILD_VERSION=$UPSTREAM-$BUILD_VERSION_SUFFIX
elif [[ ! -z $TAG ]]; then
BUILD_VERSION=$UPSTREAM-$TAG
else
BUILD_VERSION=$UPSTREAM
fi
fi

if [[ -z $GID ]]; then
GID=$(id -g)
fi

# builder image
BUILD_IMAGE=statshouse_builder_$NAME_RELEASE
docker image build -t $BUILD_IMAGE - <<EOF
FROM $IMAGE
RUN $DNF update -y
RUN $DNF group install -y "Development Tools"
RUN curl -L https://go.dev/dl/go$GOLANG_VERSION.linux-amd64.tar.gz | tar -C /usr/local -xzf -
ENV PATH=\$PATH:/usr/local/go/bin
RUN groupadd -g $GID builder
RUN useradd -u $UID -g $GID builder
EOF

# frontend
if [ ! -d cmd/statshouse-api/build ]; then
if [[ -z $NODE_IMAGE ]]; then
NODE_IMAGE="node:18-bullseye"
echo "Node image is not specified, using $NODE_IMAGE"
fi
docker run --rm -u "$UID:$GID" -v "$PWD:/src" -w /src -e REACT_APP_BUILD_VERSION="$REACT_APP_BUILD_VERSION" $NODE_IMAGE make build-sh-ui
fi

# backend & RPM
GOCACHE=build/go-cache
mkdir -p "$PWD/$GOCACHE"
docker run -i --rm -u "$UID:$GID" -v "$PWD:/src" -w /src \
-e BUILD_MACHINE="$(uname -n -m -r -s)" \
-e BUILD_VERSION="$UPSTREAM" \
-e BUILD_COMMIT="$(git log --format="%H" -n 1)" \
-e BUILD_COMMIT_TS="$(git log --format="%ct" -n 1)" \
-e GOCACHE="/src/$GOCACHE" -e BUILD_TRUSTED_SUBNET_GROUPS \
-e BUILD_ID \
-e BUILD_TIME \
$BUILD_IMAGE /bin/bash <<EOF
set -x &&\
make build-sh build-sh-metadata build-sh-api &&\
mkdir -p BUILD BUILDROOT SOURCES SPECS SRPMS RPMS &&\
cp build/statshouse.spec SPECS/statshouse.spec &&\
BUILD_VERSION=\$(echo $BUILD_VERSION | sed -e 's:-:.:g') &&\
rpmbuild --define "_topdir \$(pwd)" --define "BUILD_VERSION \$BUILD_VERSION" --define "OS_NAME_RELEASE $NAME_RELEASE" -bb SPECS/statshouse.spec &&\
rm -rf BUILD BUILDROOT SOURCES SPECS SRPMS &&\
true
EOF

shift
done
2 changes: 1 addition & 1 deletion build/statshouse.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mkdir -p %{buildroot}/usr/lib/statshouse-api/statshouse-ui/
install -m 755 %{_topdir}/target/statshouse-api %{buildroot}/usr/bin/
install -m 755 %{_topdir}/target/statshouse %{buildroot}/usr/share/engine/bin
install -m 755 %{_topdir}/target/statshouse-metadata %{buildroot}/usr/share/engine/bin
cp -a %{_topdir}/statshouse-ui/build/* %{buildroot}/usr/lib/statshouse-api/statshouse-ui/
cp -a %{_topdir}/cmd/statshouse-api/build/* %{buildroot}/usr/lib/statshouse-api/statshouse-ui/
install -m 444 %{_topdir}/cmd/statshouse-api/statshouse-api.service %{buildroot}/usr/lib/systemd/system/
install -m 444 %{_topdir}/cmd/statshouse/statshouse.service %{buildroot}/usr/lib/systemd/system/

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
all:
image: vkcom/statshouse-localrun-all
image: vkcom/statshouse-localrun-all:latest
container_name: sh
user: "root:root"
ports:
Expand Down

0 comments on commit 551ea75

Please sign in to comment.