Skip to content

Commit

Permalink
Support packaging with mule (algorand#955)
Browse files Browse the repository at this point in the history
* Support packaging with mule

* Added env vars in yaml file after adding support in `mule`

* Added `GOPROXY` back to dockerfiles

* Fixed FULLVERSION

* Use build artifacts in tmp/ from build step rather than $GOPATH/bin

* Remove `volumes` config that is no longer needed
  • Loading branch information
btoll authored Apr 21, 2020
1 parent 61cef96 commit e5c19f0
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 15 deletions.
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,6 @@ install: build

.PHONY: default fmt vet lint check_shell sanity cover prof deps build test fulltest shorttest clean cleango deploy node_exporter install %gen gen NONGO_BIN

### TARGETS FOR CICD PROCESS
###### TARGETS FOR CICD PROCESS ######
include Makefile.mule

ci-deps:
scripts/configure_dev-deps.sh && \
scripts/check_deps.sh

ci-build: buildsrc gen
mkdir -p $(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH) && \
PKG_ROOT=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH) NO_BUILD=True VARIATIONS=$(OS_TYPE)/$(ARCH) scripts/build_packages.sh $(OS_TYPE)/$(ARCH)
31 changes: 31 additions & 0 deletions Makefile.mule
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is imported into go-algorand/Makefile.

.PHONY: ci-clean ci-deps ci-setup ci-build package package-deb package-rpm package-$(OS_TYPE)-$(ARCH) package-deb-$(OS_TYPE)-$(ARCH) package-rpm-$(OS_TYPE)-$(ARCH)

ci-clean:
rm -rf tmp

ci-deps:
scripts/configure_dev-deps.sh && \
scripts/check_deps.sh

ci-setup:
mkdir -p $(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)

ci-build: ci-setup buildsrc gen
PKG_ROOT=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH) \
NO_BUILD=True VARIATIONS=$(OS_TYPE)/$(ARCH) \
scripts/build_packages.sh $(OS_TYPE)/$(ARCH)

package-$(OS_TYPE)-$(ARCH): package-deb-$(OS_TYPE)-$(ARCH) package-rpm-$(OS_TYPE)-$(ARCH)

package-deb-$(OS_TYPE)-$(ARCH):
scripts/release/mule/package/$(OS_TYPE)/$(ARCH)/deb/package.sh $(OS_TYPE) $(ARCH) $$WORKDIR

package-rpm-$(OS_TYPE)-$(ARCH):
scripts/release/mule/package/$(OS_TYPE)/$(ARCH)/rpm/package.sh $(OS_TYPE) $(ARCH) $$WORKDIR

package: package-$(OS_TYPE)-$(ARCH)
package-deb: package-deb-$(OS_TYPE)-$(ARCH)
package-rpm: package-rpm-$(OS_TYPE)-$(ARCH)

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH \
BUILDCHANNEL=${BUILDCHANNEL} \
DEFAULTNETWORK=${DEFAULTNETWORK} \
FULLVERSION=${FULLVERSION} \
PKG_ROOT=${PKG_ROOT} \
GOPROXY=https://gocenter.io
GOPROXY=https://gocenter.io \
PKG_ROOT=${PKG_ROOT}
WORKDIR $GOPATH/src/github.com/algorand/go-algorand
RUN make ci-deps && make clean
RUN rm -rf $GOPATH/src/github.com/algorand/go-algorand && \
mkdir -p $GOPATH/src/github.com/algorand/go-algorand
RUN echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
CMD ["/bin/bash"]

29 changes: 29 additions & 0 deletions docker/build/cicd.ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG ARCH="amd64"

FROM ${ARCH}:18.04
ENV GOLANG_VERSION 1.12
ARG ARCH="amd64"
RUN apt-get update && apt-get install -y build-essential git libboost-all-dev wget sqlite3 autoconf jq bsdmainutils shellcheck
WORKDIR /root
RUN wget https://dl.google.com/go/go${GOLANG_VERSION}.linux-${ARCH%v*}.tar.gz \
&& tar -xvf go${GOLANG_VERSION}.linux-${ARCH%v*}.tar.gz && \
mv go /usr/local
ENV GOROOT=/usr/local/go \
GOPATH=$HOME/go
RUN mkdir -p $GOPATH/src/github.com/algorand
COPY . $GOPATH/src/github.com/algorand/go-algorand
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH \
BRANCH=${BRANCH} \
CHANNEL=${CHANNEL} \
BUILDCHANNEL=${BUILDCHANNEL} \
DEFAULTNETWORK=${DEFAULTNETWORK} \
FULLVERSION=${FULLVERSION} \
GOPROXY=https://gocenter.io \
PKG_ROOT=${PKG_ROOT}
WORKDIR $GOPATH/src/github.com/algorand/go-algorand
RUN make ci-deps && make clean
RUN rm -rf $GOPATH/src/github.com/algorand/go-algorand && \
mkdir -p $GOPATH/src/github.com/algorand/go-algorand
RUN echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
CMD ["/bin/bash"]

11 changes: 6 additions & 5 deletions installer/rpm/algorand.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name: algorand
Name: @PKG_NAME@
Version: @VER@
Release: 1
Summary: Algorand node software
Expand All @@ -18,17 +18,17 @@ This package provides an implementation of the Algorand protocol.
%include %{LICENSE_FILE}

%prep
## Nothing to prep; intended to be built using scripts/build_rpm.sh
## Nothing to prep; intended to be built using scripts/release/mule/package/{OS_TYPE}/{ARCH}/rpm/package.sh

%build
## Nothing to prep; intended to be built using scripts/build_rpm.sh
## Nothing to prep; intended to be built using scripts/release/mule/package/{OS_TYPE}/{ARCH}/rpm/package.sh

%install
mkdir -p %{buildroot}/usr/bin
# NOTE: keep in sync with scripts/build_deb.sh bin_files
# NOTE: keep in sync with %files section below
for f in algocfg algod algoh algokey carpenter catchupsrv ddconfig.sh diagcfg goal kmd msgpacktool node_exporter; do
install -m 755 ${GOPATH}/bin/${f} %{buildroot}/usr/bin/${f}
install -m 755 ${ALGO_BIN}/${f} %{buildroot}/usr/bin/${f}
done

mkdir -p %{buildroot}/var/lib/algorand
Expand Down Expand Up @@ -63,7 +63,7 @@ if [ "%{RELEASE_GENESIS_PROCESS}" != "x" ]; then
done
cp %{buildroot}/var/lib/algorand/genesis/${DEFAULT_RELEASE_NETWORK}/genesis.json %{buildroot}/var/lib/algorand/genesis.json
else
cp installer/genesis/${DEFAULTNETWORK}/genesis.json %{buildroot}/var/lib/algorand/genesis.json
cp ${REPO_DIR}/installer/genesis/${DEFAULTNETWORK}/genesis.json %{buildroot}/var/lib/algorand/genesis.json
#${GOPATH}/bin/buildtools genesis ensure -n ${DEFAULT_RELEASE_NETWORK} --source ${REPO_DIR}/gen/${DEFAULT_RELEASE_NETWORK}/genesis.json --target %{buildroot}/var/lib/algorand/genesis.json --releasedir ${REPO_DIR}/installer/genesis
fi

Expand Down Expand Up @@ -113,3 +113,4 @@ chown -R algorand:algorand /var/lib/algorand
%postun
%systemd_postun_with_restart algorand
%systemd_postun_with_restart algorand@*

52 changes: 52 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
tasks:
- task: docker.Version
configFilePath: scripts/configure_dev-deps.sh

- task: shell.docker.Ensure
name: rpm
image: algorand/go-algorand-ci-linux-centos
version: '{{ docker.Version.outputs.version }}'
dockerFilePath: docker/build/cicd.centos.Dockerfile
dependencies: docker.Version

- task: shell.docker.Ensure
name: deb
image: algorand/go-algorand-ci-linux-ubuntu
version: '{{ docker.Version.outputs.version }}'
dockerFilePath: docker/build/cicd.ubuntu.Dockerfile
dependencies: docker.Version

- task: docker.Make
name: build
docker:
image: algorand/go-algorand-ci-linux-centos
version: '{{ docker.Version.outputs.version }}'
workDir: /projects/go-algorand
target: ci-build

- task: docker.Make
name: rpm
docker:
image: algorand/go-algorand-ci-linux-centos
version: '{{ docker.Version.outputs.version }}'
workDir: /projects/go-algorand
target: package-rpm WORKDIR=/projects/go-algorand

- task: docker.Make
name: deb
docker:
image: algorand/go-algorand-ci-linux-ubuntu
version: '{{ docker.Version.outputs.version }}'
workDir: /projects/go-algorand
target: package-deb WORKDIR=/projects/go-algorand

jobs:
package:
configs:
arch: amd64
tasks:
- shell.docker.Ensure.rpm
- docker.Make.rpm
- shell.docker.Ensure.deb
- docker.Make.deb

129 changes: 129 additions & 0 deletions scripts/release/mule/package/linux/amd64/deb/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env bash
# shellcheck disable=2038,2064

set -ex

echo
date "+build_release begin PACKAGE DEB stage %Y%m%d_%H%M%S"
echo

OS_TYPE="$1"
ARCH="$2"
WORKDIR="$3"

if [ -z "$OS_TYPE" ] || [ -z "$ARCH" ] || [ -z "$WORKDIR" ]; then
echo OS, ARCH and WORKDIR variables must be defined.
exit 1
fi

REPO_DIR="$WORKDIR"
BRANCH=$("$REPO_DIR/scripts/compute_branch.sh")
CHANNEL=$("$REPO_DIR/scripts/compute_branch_channel.sh" "$BRANCH")
BASE="$REPO_DIR/tmp/node_pkgs/$OS_TYPE/$ARCH"
mkdir -p "$BASE/$CHANNEL/$OS_TYPE-$ARCH/bin"
ALGO_BIN="$BASE/$CHANNEL/$OS_TYPE-$ARCH/bin"
mkdir -p "$BASE/pkg"
OUTDIR="$BASE/pkg"
PKG_NAME=$("$REPO_DIR/scripts/compute_package_name.sh" "${CHANNEL:-stable}")

echo "Building debian package for '${OS} - ${ARCH}'"

VER=$("$REPO_DIR/scripts/compute_build_number.sh" -f)

if [ "${DEFAULTNETWORK}" = "" ]; then
DEFAULTNETWORK=$("$REPO_DIR/scripts/compute_branch_network.sh")
fi
DEFAULT_RELEASE_NETWORK=$("$REPO_DIR/scripts/compute_branch_release_network.sh" "${DEFAULTNETWORK}")

PKG_ROOT=$(mktemp -d)
trap "rm -rf $PKG_ROOT" 0

mkdir -p "${PKG_ROOT}/usr/bin"

# NOTE: keep in sync with installer/rpm/algorand.spec
bin_files=("algocfg" "algod" "algoh" "algokey" "carpenter" "catchupsrv" "ddconfig.sh" "diagcfg" "goal" "kmd" "msgpacktool" "node_exporter")

for binary in "${bin_files[@]}"; do
cp "${ALGO_BIN}/${binary}" "${PKG_ROOT}"/usr/bin
chmod 755 "${PKG_ROOT}/usr/bin/${binary}"
done

mkdir -p "${PKG_ROOT}/usr/lib/algorand"
lib_files=("updater" "find-nodes.sh")
for lib in "${lib_files[@]}"; do
cp "${ALGO_BIN}/${lib}" "${PKG_ROOT}/usr/lib/algorand"
chmod g-w "${PKG_ROOT}/usr/lib/algorand/${lib}"
done

data_files=("config.json.example" "system.json")
mkdir -p "${PKG_ROOT}/var/lib/algorand"
for data in "${data_files[@]}"; do
cp "installer/${data}" "${PKG_ROOT}/var/lib/algorand"
done

if [ ! -z "${RELEASE_GENESIS_PROCESS}" ]; then
genesis_dirs=("devnet" "testnet" "mainnet" "betanet")
for dir in "${genesis_dirs[@]}"; do
mkdir -p "${PKG_ROOT}/var/lib/algorand/genesis/${dir}"
cp "${REPO_DIR}/installer/genesis/${dir}/genesis.json" "${PKG_ROOT}/var/lib/algorand/genesis/${dir}/genesis.json"
done
# Copy the appropriate network genesis.json for our default (in root ./genesis folder)
cp "${PKG_ROOT}/var/lib/algorand/genesis/${DEFAULT_RELEASE_NETWORK}/genesis.json" "${PKG_ROOT}/var/lib/algorand"
elif [[ "${CHANNEL}" == "dev" || "${CHANNEL}" == "stable" || "${CHANNEL}" == "nightly" || "${CHANNEL}" == "beta" ]]; then
cp "${REPO_DIR}/installer/genesis/${DEFAULTNETWORK}/genesis.json" "${PKG_ROOT}/var/lib/algorand/genesis.json"
else
cp "${REPO_DIR}/installer/genesis/${DEFAULTNETWORK}/genesis.json" "${PKG_ROOT}/var/lib/algorand"
fi

systemd_files=("algorand.service" "algorand@.service")
mkdir -p "${PKG_ROOT}/lib/systemd/system"
for svc in "${systemd_files[@]}"; do
cp "installer/${svc}" "${PKG_ROOT}/lib/systemd/system"
chmod 644 "${PKG_ROOT}/lib/systemd/system/${svc}"
done

unattended_upgrades_files=("51algorand-upgrades")
mkdir -p "${PKG_ROOT}/etc/apt/apt.conf.d"
for f in "${unattended_upgrades_files[@]}"; do
< "installer/${f}" \
sed -e "s,@CHANNEL@,${CHANNEL}," \
> "${PKG_ROOT}/etc/apt/apt.conf.d/${f}"
done

# files should not be group writable but directories should be
chmod -R g-w "${PKG_ROOT}/var/lib/algorand"
find "${PKG_ROOT}/var/lib/algorand" -type d | xargs chmod g+w

mkdir -p "${PKG_ROOT}/DEBIAN"
debian_files=("control" "preinst" "postinst" "prerm" "postrm" "conffiles")
for ctl in "${debian_files[@]}"; do
# Copy first, to preserve permissions, then overwrite to fill in template.
cp -a "installer/debian/${ctl}" "${PKG_ROOT}/DEBIAN/${ctl}"
< "installer/debian/${ctl}" \
sed -e "s,@ARCH@,${ARCH}," \
-e "s,@VER@,${VER}," \
-e "s,@PKG_NAME@,${PKG_NAME}," \
> "${PKG_ROOT}/DEBIAN/${ctl}"
done
# TODO: make `Files:` segments for vendor/... and crypto/libsodium-fork, but reasonably this should be understood to cover all _our_ files and copied in packages continue to be licenced under their own terms
cat <<EOF> "${PKG_ROOT}/DEBIAN/copyright"
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Algorand
Upstream-Contact: Algorand developers <dev@algorand.com>
Source: https://github.com/algorand/go-algorand
Files: *
Copyright: Algorand developers <dev@algorand.com>
License: AGPL-3+
EOF
sed 's/^$/./g' < COPYING | sed 's/^/ /g' >> "${PKG_ROOT}/DEBIAN/copyright"
mkdir -p "${PKG_ROOT}/usr/share/doc/algorand"
cp -p "${PKG_ROOT}/DEBIAN/copyright" "${PKG_ROOT}/usr/share/doc/algorand/copyright"
OUTPUT="$OUTDIR/algorand_${VER}_${ARCH}.deb"
dpkg-deb --build "${PKG_ROOT}" "${OUTPUT}"
echo
date "+build_release end PACKAGE DEB stage %Y%m%d_%H%M%S"
echo
45 changes: 45 additions & 0 deletions scripts/release/mule/package/linux/amd64/rpm/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -ex

echo "Building RPM package"

OS_TYPE="$1"
ARCH="$2"
WORKDIR="$3"

if [ -z "$OS_TYPE" ] || [ -z "$ARCH" ] || [ -z "$WORKDIR" ]; then
echo OS, ARCH and WORKDIR variables must be defined.
exit 1
fi

REPO_DIR="$WORKDIR"
FULLVERSION=$("$REPO_DIR/scripts/compute_build_number.sh" -f)
BRANCH=$("$REPO_DIR/scripts/compute_branch.sh")
CHANNEL=$("$REPO_DIR/scripts/compute_branch_channel.sh" "$BRANCH")
ALGO_BIN="$REPO_DIR/tmp/node_pkgs/$OS_TYPE/$ARCH/$CHANNEL/$OS_TYPE-$ARCH/bin"
# TODO: Should there be a default network?
DEFAULTNETWORK=devnet
DEFAULT_RELEASE_NETWORK=$("$REPO_DIR/scripts/compute_branch_release_network.sh" "${DEFAULTNETWORK}")

# The following need to be exported for use in ./go-algorand/installer/rpm/algorand.spec.
export DEFAULT_NETWORK
export DEFAULT_RELEASE_NETWORK
export REPO_DIR
export ALGO_BIN

RPMTMP=$(mktemp -d 2>/dev/null || mktemp -d -t "rpmtmp")
trap 'rm -rf $RPMTMP' 0

TEMPDIR=$(mktemp -d)
trap 'rm -rf $TEMPDIR' 0
< "$REPO_DIR/installer/rpm/algorand.spec" \
sed -e "s,@PKG_NAME@,${PKG_NAME:-algorand}," \
-e "s,@VER@,$FULLVERSION," \
> "$TEMPDIR/algorand.spec"

rpmbuild --buildroot "$HOME/foo" --define "_rpmdir $RPMTMP" --define "RELEASE_GENESIS_PROCESS x$RELEASE_GENESIS_PROCESS" --define "LICENSE_FILE ./COPYING" -bb "$TEMPDIR/algorand.spec"

mkdir -p "$REPO_DIR/tmp/node_pkgs/$OS_TYPE/$ARCH/pkg"
cp -p "$RPMTMP"/*/*.rpm "$REPO_DIR/tmp/node_pkgs/$OS_TYPE/$ARCH/pkg"

0 comments on commit e5c19f0

Please sign in to comment.