Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Add .cirrus.yml for FreeBSD (amd64, i386) CI/CD #2911

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
freebsd_instance:
image_family: freebsd-11-3-snap

freebsd_build_task:

#
# We support only node versions available in the FreeBSD ports tree
# Currently supported node versions can be figured out as follows:
#
# Check the node versions supported by the npm port:
# https://svnweb.freebsd.org/ports/head/www/npm/Makefile?view=markup
#
# www/npm port contains options to build with different node engines
# in the form of
# xxx_RUN_DEPENDS= node>0.8:pppppp
# "ppppp" above is the port name, for example www/node12
#
# "www/node" port is the latest and its is a moving target
# You have to check its Makefile to figure out which version it represents:
# https://svnweb.freebsd.org/ports/head/www/node/Makefile?view=markup
#
# Typically this means once www/node gets promoted from node 19 to 20
# "- package: npm-node19" needs to be added before the "package: npm"
# line.
#
env:
matrix:
- package: npm-node10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we expand out the matrix to the other versions we currently list as supported for FreeBSD?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I forgot it. Back to work :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can limit this to v5 also to make our lives a bit easier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been only building binaries for node version currently in the FreeBSD ports tree, which are 10, 12 and 13 now. Pushed the commit to expand the matrix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop 10 now, but it would be good to try and get 12, 14, 16, 17 to match the other platforms

- package: npm-node12
- package: npm

env:
matrix:
- abi: freebsd:11:x86:64
REPOS_DIR: .cirrus/pkg/repos
- abi: freebsd:11:x86:32
jail_name: j11i386
exec_prefix: cbsd jexec jname=j11i386
working_dir: /etc/skel
REPOS_DIR: /etc/skel/.cirrus/pkg/repos

env:
GH_API_TOKEN: ENCRYPTED[5e482f417304528148bb96eca8d030eacd6ab9972d482485fc4d42907283b995f658b351e0676e9493a37d815398f541]
SKIP_SASS_BINARY_DOWNLOAD_FOR_CI: yes
CPPFLAGS: -I/usr/local/include

prepare_script:
- pkg -R .cirrus/pkg/repos update -f;
- |
if test "$abi" = "freebsd:11:x86:32"; then
pkg -R .cirrus/pkg/repos install -y cbsd
./scripts/configure_freebsd_ci_jail.sh $jail_name $CIRRUS_WORKING_DIR;
$exec_prefix pkg update -f
fi
- $exec_prefix pkg install -y "${package}" python2 git-lite
- $exec_prefix node --version
- $exec_prefix npm --version
- $exec_prefix clang++ --version

build_script:
- |
if [ -n "${working_dir}" ]; then change_dir="cd ${working_dir} &&"; fi
echo "$change_dir npm install --unsafe-perm --production --nodedir=/usr/local" | $exec_prefix /bin/sh
echo "Generated files:"
echo "$change_dir find vendor" | $exec_prefix /bin/sh

publish_task:
only_if: $CIRRUS_TAG != ""
script:
- |
for file in `ls vendor/**/*.node`; do
parent=${file%/*};
name=${parent##*/};
fullyQualifiedName="$(pwd)/$parent/${name}_binding.node";
mv "$file" "$parent/${name}_binding.node";
echo -e "New filename\072 $fullyQualifiedName";
./scripts/upload-github-release-asset.sh github_api_token=$GH_API_TOKEN owner=sass repo=node-sass tag=$CIRRUS_TAG filename=$fullyQualifiedName;
done
7 changes: 7 additions & 0 deletions .cirrus/pkg/repos/FreeBSD.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FreeBSD: {
url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
mirror_type: "srv",
signature_type: "fingerprints",
fingerprints: "/usr/share/keys/pkg",
enabled: yes
}
85 changes: 85 additions & 0 deletions scripts/configure_freebsd_ci_jail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env sh

set -o xtrace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set -e?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to rewrite both of those shell scripts but forgot about them (didn't test upload either). Resetting to draft. Thanks!


jailName=$1
skelDirectory=$2
cbsd_workdir=/usr/jails
jail_arch="i386"
jail_ver="11.3"

# determine uplink ip address
# determine uplink iface
echo "Interface configuration:"
/sbin/ifconifg -a
auto_iface=$( /sbin/route -n get 0.0.0.0 |/usr/bin/awk '/interface/{print $2}' )
my_ipv4=$( /sbin/ifconfig ${auto_iface} | /usr/bin/awk '/inet [0-9]+/{print $2}' )

if [ -z "${my_ipv4}" ]; then
echo "IPv4 not detected"
exit 1
fi
echo "IPv4 routing table:"
netstat -rnf inet
echo "IPv6 routing table:"
netstat -rnf inet6
echo "${auto_iface} has been selected, with ${my_ipv4} IPv4 address"

echo "Writing '${jailName}' configuration file"
cat > /tmp/${jailName}.jconf << EOF
jname="${jailName}"
path="${cbsd_workdir}/${jailName}"
host_hostname="${jailName}.my.domain"
ip4_addr="${my_ipv4}"
mount_devfs="1"
allow_mount="1"
allow_devfs="1"
allow_nullfs="1"
allow_raw_sockets="1"
mount_fstab="${cbsd_workdir}/jails-fstab/fstab.${jailName}"
arch="${jail_arch}"
mkhostsfile="1"
devfs_ruleset="4"
ver="${jail_ver}"
basename=""
baserw="0"
mount_src="0"
mount_obj="0"
mount_kernel="0"
mount_ports="1"
astart="1"
data="${cbsd_workdir}/jails-data/${jailName}-data"
vnet="0"
applytpl="1"
mdsize="0"
rcconf="${cbsd_workdir}/jails-rcconf/rc.conf_${jailName}"
floatresolv="1"
exec_poststart="0"
exec_poststop=""
exec_prestart="0"
exec_prestop="0"
exec_master_poststart="0"
exec_master_poststop="0"
exec_master_prestart="0"
exec_master_prestop="0"
pkg_bootstrap="1"
interface="0"
jailskeldir="$skelDirectory"
exec_start="/bin/sh /etc/rc"
exec_stop="/bin/sh /etc/rc.shutdown"
EOF

echo "Initializing cbsd environment"
env workdir=${cbsd_workdir} /usr/local/cbsd/sudoexec/initenv /usr/local/cbsd/share/initenv.conf

echo "Creating ${jailName}"
cbsd jcreate jconf=/tmp/${jailName}.jconf inter=0
cbsd jailscp /etc/resolv.conf ${jailName}:/etc/resolv.conf

cat > ~cbsd/jails-fstab/fstab.${jailName}.local <<EOF
${skelDirectory} /etc/skel nullfs rw 0 0
EOF

cbsd jstart jname=${jailName} inter=0

echo "${jailName} created"
60 changes: 60 additions & 0 deletions scripts/upload-github-release-asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env sh
#
# Modified version of: https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
# * repo
# * tag
# * filename
# * github_api_token
#
# Script to upload a release asset using the GitHub API v3.
#
# Example:
#
# upload-github-release-asset.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 filename=./build.zip
#

set -e

# Validate settings.
[ "$TRACE" ] && set -x

for line in "$@"; do
eval "$line"
done

# Define variables.
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/$owner/$repo"
GH_RELEASES="$GH_REPO/releases"
GH_TAGS="$GH_RELEASES/tags/$tag"
AUTH="Authorization: token $github_api_token"

if test "$tag" == "LATEST"; then
GH_TAGS="$GH_REPO/releases/latest"
fi

# Validate token.
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }

# Create a release from tag if it does not exist.
curl -s -d "{\"tag_name\":\"$tag\"}" -H "$AUTH" "$GH_RELEASES" > /dev/null

# Read asset tags.
response=$(curl -sH "$AUTH" $GH_TAGS)

# Get ID of the asset based on given filename.
eval "$(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')"
[ -n "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; }

# Upload asset
echo "Uploading asset... "

# Construct url
GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$id/assets?name=$(basename $filename)"

curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET