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

refactor(build): wip for arm64 #95

Draft
wants to merge 4 commits into
base: main
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
6 changes: 5 additions & 1 deletion config_golang.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# golang
GOLANG?=1.20.3
GOLANG_HASH?=979694c2c25c735755bf26f4f45e19e64e4811d661dd07b8c010f7a8e18adfca
GOLANG_HASH_AMD64?=979694c2c25c735755bf26f4f45e19e64e4811d661dd07b8c010f7a8e18adfca
GOLANG_HASH_ARM64?=eb186529f13f901e7a2c4438a05c2cd90d74706aaa0a888469b2a4a617b6ee54
GOLANG_DLV?=v1.20.2
GOLANG_LINTER?=v1.52.2

ARCH_UPPER=$(shell echo "$(strip $(ARCH))"|tr '[:lower:]' '[:upper:]')
GOLANG_HASH=$(GOLANG_HASH_$(ARCH_UPPER))
2 changes: 2 additions & 0 deletions images/go-devel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build: $(STACKER)
--substitute DISTRO_REL=$(DISTRO_REL) \
--substitute GOLANG=$(GOLANG) \
--substitute GOLANG_HASH=$(GOLANG_HASH) \
--substitute GOLANG_HASH_AMD64=$(GOLANG_HASH_AMD64) \
--substitute GOLANG_DLV=$(GOLANG_DLV) \
--substitute GOLANG_LINTER=$(GOLANG_LINTER)

Expand All @@ -53,6 +54,7 @@ publish: $(STACKER)
--substitute DISTRO_REL=$(DISTRO_REL) \
--substitute GOLANG=$(GOLANG) \
--substitute GOLANG_HASH=$(GOLANG_HASH) \
--substitute GOLANG_HASH_AMD64=$(GOLANG_HASH_AMD64) \
--substitute GOLANG_DLV=$(GOLANG_DLV) \
--substitute GOLANG_LINTER=$(GOLANG_LINTER) \
--url $(PUBLISH_URL)/$(DISTRO) \
Expand Down
56 changes: 38 additions & 18 deletions images/go-devel/stacker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,54 @@ build-go-devel:
export GOLANG_LINTER=${{GOLANG_LINTER}}
# source pkgmgr func defs
. /stacker/pkgmgr/defs.sh
# prepare the rootfs

# install go for cross compilation in the build environment
dldir=$(mktemp -d ${TMPDIR:-/tmp}/XXXXXX)
# install go
wget -N https://go.dev/dl/go${GOLANG}.${OS}-${ARCH}.tar.gz -O $dldir/golang.tar.gz
echo "${{GOLANG_HASH}} $dldir/golang.tar.gz" > SHA256SUMS
wget -N https://go.dev/dl/go${GOLANG}.${OS}-amd64.tar.gz -O $dldir/golang.tar.gz
echo "${{GOLANG_HASH_AMD64}} $dldir/golang.tar.gz" > SHA256SUMS
sha256sum -c SHA256SUMS
rm SHA256SUMS
tar xvzf $dldir/golang.tar.gz -C /opt/
export GOROOT=/opt/go
export PATH=$GOROOT/bin:$PATH
mkdir -p /go
export GOPATH=/go
export PATH=$GOPATH/bin:$PATH
export GOCACHE=/go/cache
# build golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANG_LINTER}

# prepare the rootfs
mkdir -p /rootfs_diff/opt

# install go and other tools as needed in the final image
dldir=$(mktemp -d ${TMPDIR:-/tmp}/XXXXXX)
wget -N https://go.dev/dl/go${GOLANG}.${OS}-${ARCH}.tar.gz -O $dldir/golang.tar.gz
echo "${{GOLANG_HASH}} $dldir/golang.tar.gz" > SHA256SUMS
sha256sum -c SHA256SUMS
tar xzvf $dldir/golang.tar.gz -C /rootfs_diff/opt/

# install golangci-lint
linter_ver=$(echo ${GOLANG_LINTER} | cut -c2-)
wget -N https://github.com/golangci/golangci-lint/releases/download/${GOLANG_LINTER}/golangci-lint-${linter_ver}-linux-${ARCH}.tar.gz -O $dldir/golangci-lint.tar.gz
tar -xzvf $dldir/golangci-lint.tar.gz --strip-components=1
mv golangci-lint /rootfs_diff/opt/go/bin/

# build dlv debugger
go install github.com/go-delve/delve/cmd/dlv@${GOLANG_DLV}
# copy binaries under /opt/bin
mkdir -p /rootfs_diff/opt/bin
tar xvzf $dldir/golang.tar.gz -C /rootfs_diff/opt/
cp $GOPATH/bin/golangci-lint /rootfs_diff/opt/go/bin/
cp $GOPATH/bin/dlv /rootfs_diff/opt/go/bin/
GOOS=linux GOARCH=${ARCH} go install github.com/go-delve/delve/cmd/dlv@${GOLANG_DLV}
ls -l $GOPATH/bin/
if [ "${ARCH}" = "amd64" ] ; then
cp $GOPATH/bin/dlv /rootfs_diff/opt/go/bin/
else
cp $GOPATH/bin/linux_${ARCH}/dlv /rootfs_diff/opt/go/bin/
fi

# set the new profile/environment variables
mkdir -p /rootfs_diff/etc/
echo 'export HOME=/go' > /rootfs_diff/etc/profile
echo 'export GOROOT=/opt/go' >> /rootfs_diff/etc/profile
echo 'export PATH=$GOROOT/bin:$PATH' >> /rootfs_diff/etc/profile
echo 'mkdir -p /tmp/go/cache' >> /rootfs_diff/etc/profile
echo 'export GOCACHE=/tmp/go/cache' >> /rootfs_diff/etc/profile

# cleanup unnecessary files
cleanup_rootfs /rootfs_diff
build_only: true
Expand All @@ -53,12 +79,6 @@ go-devel-${{ARCH}}:
- path: stacker://build-go-devel/rootfs_diff/
dest: /
- ../../pkgmgr # The import purpose is to force a rebuild if file changed
run: |
echo 'export HOME=/go' > /etc/profile
echo 'export GOROOT=/opt/go' >> /etc/profile
echo 'export PATH=$GOROOT/bin:$PATH' >> /etc/profile
echo 'mkdir -p /tmp/go/cache' >> /etc/profile
echo 'export GOCACHE=/tmp/go/cache' >> /etc/profile
full_command: "/bin/sh -l"
annotations:
org.opencontainers.image.title: go-devel-${{ARCH}}
Expand Down
9 changes: 5 additions & 4 deletions images/openj9-devel/stacker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ build-openj9-devel:
. /stacker/$DISTRO-pkgs.sh
# install pkgs
install_pkgs_from_file /rootfs_diff /stacker/${{DISTRO}}-pkgs-${{ARCH}}
# set the new profile/environment variables
mkdir -p /rootfs_diff/etc/
echo 'export HOME=/jdk' > /rootfs_diff/etc/profile
echo 'export JAVA_HOME=/opt/jdk' >> /rootfs_diff/etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /rootfs_diff/etc/profile
# cleanup unnecessary files, do not use the cleanup_rootfs function as it deletes necessary files
rm -rf /rootfs_diff/tmp/*
rm -rf /rootfs_diff/var/*
Expand All @@ -53,10 +58,6 @@ openj9-devel-${{ARCH}}:
- ${{DISTRO}}-pkgs.sh # The import purpose is to force a rebuild if file changed
- ${{DISTRO}}-pkgs-${{ARCH}} # The import purpose is to force a rebuild if file changed
- ../../pkgmgr # The import purpose is to force a rebuild if file changed
run: |
echo 'export HOME=/jdk' > /etc/profile
echo 'export JAVA_HOME=/opt/jdk' >> /etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
full_command: "/bin/sh -l"
annotations:
org.opencontainers.image.title: openj9-devel-${{ARCH}}
Expand Down
9 changes: 5 additions & 4 deletions images/openj9/stacker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ build-openj9:
install_pkgs_from_file /rootfs_diff /stacker/${{DISTRO}}-pkgs-${{ARCH}}
# install busybox
install_busybox /rootfs_diff
# set the new profile/environment variables
mkdir -p /rootfs_diff/etc/
echo 'export HOME=/jre' > /rootfs_diff/etc/profile
echo 'export JAVA_HOME=/opt/jre' >> /rootfs_diff/etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /rootfs_diff/etc/profile
# cleanup unnecessary files, do not use the cleanup_rootfs function as it deletes necessary files
rm -rf /rootfs_diff/tmp/*
rm -rf /rootfs_diff/var/*
Expand All @@ -56,10 +61,6 @@ openj9-${{ARCH}}:
- ${{DISTRO}}-pkgs.sh # The import purpose is to force a rebuild if file changed
- ${{DISTRO}}-pkgs-${{ARCH}} # The import purpose is to force a rebuild if file changed
- ../../pkgmgr # The import purpose is to force a rebuild if file changed
run: |
echo 'export HOME=/jre' > /etc/profile
echo 'export JAVA_HOME=/opt/jre' >> /etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
full_command: "/bin/sh -l"
annotations:
org.opencontainers.image.title: openj9-${{ARCH}}
Expand Down
15 changes: 8 additions & 7 deletions images/rust-devel/stacker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ build-rust-devel:
cp -R ${CARGO_HOME} /rootfs_diff/opt/
# HOME folder
mkdir -p /rootfs_diff/rust/
# set the new profile/environment variables
mkdir -p /rootfs_diff/etc/
echo 'export HOME=/rust' > /rootfs_diff/etc/profile
echo 'export RUSTUP_HOME=/opt/rustup' >> /rootfs_diff/etc/profile
echo 'export CARGO_HOME=/opt/cargo' >> /rootfs_diff/etc/profile
echo 'source "/opt/cargo/env"' >> /rootfs_diff/etc/profile
echo 'export RUSTUP_TOOLCHAIN=${{RUST}}' >> /rootfs_diff/etc/profile
echo 'export SSL_CERT_DIR=/etc/ssl/certs' >> /rootfs_diff/etc/profile
# cleanup unnecessary files
# binaries were intentionally installed under /rootfs_diff/usr/bin/
# remove all docs
Expand All @@ -53,13 +61,6 @@ rust-devel-${{ARCH}}:
- path: stacker://build-rust-devel/rootfs_diff/
dest: /
- ../../pkgmgr # The import purpose is to force a rebuild if file changed
run: |
echo 'export HOME=/rust' > /etc/profile
echo 'export RUSTUP_HOME=/opt/rustup' >> /etc/profile
echo 'export CARGO_HOME=/opt/cargo' >> /etc/profile
echo 'source "/opt/cargo/env"' >> /etc/profile
echo 'export RUSTUP_TOOLCHAIN=${{RUST}}' >> /etc/profile
echo 'export SSL_CERT_DIR=/etc/ssl/certs' >> /etc/profile
full_command: "/bin/sh -l"
annotations:
org.opencontainers.image.title: rust-devel-${{ARCH}}
Expand Down
16 changes: 8 additions & 8 deletions pkgmgr/defs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ unpack_deb() {

dpkg --add-architecture "$ARCH"

old_path=$(pwd)
cd "$dldir"
DEBIAN_FRONTEND=noninteractive \
apt-get -y --reinstall install \
"--option=Dir::Cache::Archives=$dldir" \
--no-install-recommends \
--download-only \
apt-get -y download \
"$pkg":"$ARCH"
cd "$old_path"

echo DLDIR="$dldir"
ls "$dldir"
Expand All @@ -62,11 +62,11 @@ unpack_debs() {

dpkg --add-architecture "$ARCH"

old_path=$(pwd)
cd "$dldir"
DEBIAN_FRONTEND=noninteractive \
xargs apt-get -y --reinstall install \
"--option=Dir::Cache::Archives=$dldir" \
--no-install-recommends \
--download-only <$pkgs_file
xargs apt-get -y download <$pkgs_file
cd "$old_path"

echo DLDIR="$dldir"
ls "$dldir"/
Expand Down