Skip to content

Commit

Permalink
Fix packaging and install script (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
tashima42 authored Nov 14, 2023
1 parent 5d83148 commit 5bf921c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 39 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: ECM Distro Tools Release
on:
push:
tags:
- "v*"
push:
tags:
- "v*"
jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout
uses: actions/checkout@v4
- name: Build ECM Distro Tools
run: |
make all
make test
make package-binaries
- name: Publish Binaries
uses: SierraSoftworks/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
overwrite: 'true'
overwrite: "true"
files: |
${{ github.workspace }}/bin/bootstrap_hash
${{ github.workspace }}/bin/check_for_k8s_release
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
${{ github.workspace }}/cmd/gen_release_report/bin/gen_release_report-freebsd-arm64
${{ github.workspace }}/cmd/gen_release_report/bin/gen_release_report-linux-amd64
${{ github.workspace }}/cmd/gen_release_report/bin/gen_release_report-linux-arm64
${{ github.workspace }}/cmd/gen_release_report/bin/sha256sums-gen_release_report.
${{ github.workspace }}/cmd/gen_release_report/bin/sha256sums-gen_release_report.txt
${{ github.workspace }}/cmd/k3s_release/bin/k3s_release-darwin-amd64
${{ github.workspace }}/cmd/k3s_release/bin/k3s_release-darwin-arm64
${{ github.workspace }}/cmd/k3s_release/bin/k3s_release-freebsd-amd64
Expand Down Expand Up @@ -97,8 +97,12 @@ jobs:
${{ github.workspace }}/cmd/upstream_go_version/bin/upstream_go_version-linux-amd64
${{ github.workspace }}/cmd/upstream_go_version/bin/upstream_go_version-linux-arm64
${{ github.workspace }}/cmd/upstream_go_version/bin/sha256sums-upstream_go_version.txt
${{ github.workspace }}/cmd/standup/bin/standup
${{ github.workspace }}/ecm-distro-tools.tgz
${{ github.workspace }}/ecm-distro-tools.darwin-amd64.tar.gz
${{ github.workspace }}/ecm-distro-tools.darwin-arm64.tar.gz
${{ github.workspace }}/ecm-distro-tools.linux-amd64.tar.gz
${{ github.workspace }}/ecm-distro-tools.linux-arm64.tar.gz
${{ github.workspace }}/ecm-distro-tools.freebsd-amd64.tar.gz
${{ github.workspace }}/ecm-distro-tools.freebsd-arm64.tar.gz
- name: Docker Hub Login
uses: docker/login-action@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ data/*
.DS_Store

.vscode

# build artifacts
*.tar
*.tar.gz
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ build-image:
package-binaries: $(BINARIES)
@$(eval export BIN_FILES = $(shell ls bin/))

cd bin && \
tar cvf ../ecm-distro-tools.tar $(BIN_FILES) && \
cd ../

for binary in $<; do \
cd cmd/$${binary}/bin && \
tar rvf ../../../ecm-distro-tools.tar * && \
cd ../../../; \
for arch in $(ARCHS); do \
for os in $(OSs); do \
SUFFIX=$${os}-$${arch}; \
cd bin && \
tar cvf ../ecm-distro-tools.$${SUFFIX}.tar $(BIN_FILES) && \
cd ../; \
for binary in $(BINARIES); do \
cd cmd/$${binary}/bin && \
tar rvf ../../../ecm-distro-tools.$${SUFFIX}.tar $${binary}-$${SUFFIX} && \
cd ../../../; \
done; \
gzip < ecm-distro-tools.$${SUFFIX}.tar > ecm-distro-tools.$${SUFFIX}.tar.gz && \
rm -f ecm-distro-tools.$${SUFFIX}.tar; \
done; \
done

gzip < ecm-distro-tools.tar > ecm-distro-tools.tgz && \
rm -f ecm-distro-tools.tar
5 changes: 2 additions & 3 deletions cmd/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
BINARIES = gen_release_notes gen_release_report backport semv standup k3s_release rancher_release test_coverage upstream_go_version rke2_release
BINARIES = gen_release_notes gen_release_report backport semv k3s_release rancher_release test_coverage upstream_go_version rke2_release
ARCHS = amd64 arm64
OSs = linux darwin freebsd
GO_COMPILE = CGO_ENABLED=1 $(GO) build -tags $(TAGS) -v -ldflags "$(LDFLAGS)" -o $@-$${os}-$${arch}
GO_COMPILE = GOOS=$${os} GOARCH=$${arch} CGO_ENABLED=1 $(GO) build -tags $(TAGS) -v -ldflags "$(LDFLAGS)" -o $@-$${os}-$${arch}
OS := $(shell uname)

ifeq ($(OS),Darwin)
GEN_HASH = shasum -a 256 $@-$${os}-$${arch} >> $(BINDIR)/sha256sums-$(BINARY).txt
else
GEN_HASH = sha256sum $@-$${os}-$${arch} >> $(BINDIR)/sha256sums-$(BINARY).txt
endif

1 change: 1 addition & 0 deletions cmd/backport/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $(BINDIR)/$(BINARY): clean
for arch in $(ARCHS); do \
for os in $(OSs); do \
$(GO_COMPILE) ; \
$(GEN_HASH); \
done; \
done

Expand Down
35 changes: 19 additions & 16 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TMP_DIR=""
REPO_NAME="ecm-distro-tools"
REPO_URL="https://github.com/rancher/${REPO_NAME}"
REPO_RELEASE_URL="${REPO_URL}/releases"
INSTALL_DIR="/usr/local/bin/ecm-distro-tools"
INSTALL_DIR="$HOME/.local/bin/ecm-distro-tools"
SUFFIX=""
DOWNLOADER=""

Expand All @@ -31,14 +31,12 @@ setup_arch() {
# setup_tmp creates a temporary directory and cleans up when done.
setup_tmp() {
TMP_DIR=$(mktemp -d -t ecm-distro-tools-install.XXXXXXXXXX)
TMP_HASH=${TMP_DIR}/ecm-distro-tools.hash
TMP_BIN=${TMP_DIR}/ecm-distro-tools.bin
cleanup() {
code=$?
set +e
trap - EXIT
rm -rf ${TMP_DIR}
exit $code
rm -rf "${TMP_DIR}"
exit "$code"
}
trap cleanup INT EXIT
}
Expand All @@ -61,7 +59,7 @@ verify_downloader() {
download() {
case "${DOWNLOADER}" in
*curl)
curl -o "$1" -fsSL "$2"
cd "$1" && { curl -fsSLO "$2" ; cd -; }
;;
*wget)
wget -qO "$1" "$2"
Expand All @@ -80,15 +78,23 @@ download_tarball() {

echo "downloading tarball from ${TARBALL_URL}"

download "${TMP_DIR}" "$1"
download "${TMP_DIR}" "${TARBALL_URL}"
}

# install_binaries installs the binaries from the downloaded tar.
install_binaries() {
cd "${TMP_DIR}"
tar zxvf "${TMP_DIR}/$1"

find . -type f -name "*.${SUFFIX} -exec cp {} ${INSTALL_DIR}" \;
tar -xf "${TMP_DIR}/ecm-distro-tools.${SUFFIX}.tar.gz"
rm "${TMP_DIR}/ecm-distro-tools.${SUFFIX}.tar.gz"
mkdir -p "${INSTALL_DIR}"

for f in * ; do
file_name="${f}"
if echo "${f}" | grep -q "${SUFFIX}"; then
file_name=${file_name%"-${SUFFIX}"}
fi
cp "${TMP_DIR}/${f}" "${INSTALL_DIR}/${file_name}"
done
}

{ # main
Expand All @@ -104,13 +110,10 @@ install_binaries() {
setup_arch

verify_downloader curl || verify_downloader wget || fatal "error: cannot find curl or wget"
download_tarball "${RELEASE_TARBALL}"
install_binaries "${RELEASE_TARBALL}"
download_tarball
install_binaries

printf "Run command to access tools:\n\nPATH=%s:%s" "${PATH}" "${INSTALL_DIR}"
printf "Run command to access tools:\n\nPATH=%s:%s\n\n" "${PATH}" "${INSTALL_DIR}"

exit 0
}



0 comments on commit 5bf921c

Please sign in to comment.