Skip to content

Commit

Permalink
feat(release): Changed go releaser to create zip and tar archives (#266)
Browse files Browse the repository at this point in the history
* Changed go releaser to create zip and tar archives instead of binaries with all dependencies packgaed in

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

* Update buildscripts/download-dependencies.sh

Co-authored-by: Brandon Johnson <brandon.johnson@bluemedora.com>

* Added no_unique_dist_dir and fixed up dependencies

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

* Moved release-prep task into goreleaser before hook

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

* Fixed build-msi.sh binary reference

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

Co-authored-by: Brandon Johnson <brandon.johnson@bluemedora.com>
  • Loading branch information
Corbin Phelps and BinaryFissionGames authored Mar 8, 2022
1 parent 44d7c94 commit 1bbf84a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: release
on:
push:
tags:
- 'v*'
- "v*"

jobs:
build-msi:
Expand Down Expand Up @@ -34,7 +34,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Copy Windows Binary
run: cp dist/collector_windows_amd64.exe windows/observiq-collector.exe
run: cp dist/collector_windows_amd64/observiq-collector.exe windows/observiq-collector.exe
- name: Get Stanza Plugins Ref
id: plugins
run: echo "::set-output name=ref::$(Get-Content ./PLUGINS_VERSION)"
Expand All @@ -61,7 +61,7 @@ jobs:
echo "C:/build" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
# Installs go-msi and wix.
- name: Install Build Tools
run: |
run: |
curl -f -L -o go-msi.exe https://github.com/observIQ/go-msi/releases/download/v2.1.0/go-msi.exe
curl -f -L -o wix310-binaries.zip http://wixtoolset.org/downloads/v3.10.3.3007/wix310-binaries.zip
unzip wix310-binaries.zip
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
# JMX_JAR_VERSION=v1.7.0
tags: |
observiq/observiq-collector:${{ steps.get-tag.outputs.tag }}
release:
needs: [build-msi]
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
run: 'echo "$COSIGN_PRIVATE_KEY" >> cosign.key'
shell: bash
env:
COSIGN_PRIVATE_KEY : ${{secrets.ORG_COSIGN_PRIVATE_KEY}}
COSIGN_PRIVATE_KEY: ${{secrets.ORG_COSIGN_PRIVATE_KEY}}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ windows/**/wix.dynamic.json
windows/**/wix
stanza-plugins
windows/config.yaml
windows/opentelemetry-java-contrib-jmx-metrics.jar
opentelemetry-java-contrib-jmx-metrics.jar
plugins
release_deps
29 changes: 23 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
before:
hooks:
- make release-prep

# https://goreleaser.com/customization/build/
builds:
- id: collector
binary: collector_{{ .Os }}_{{ .Arch }}
binary: observiq-collector
main: ./cmd/collector
env:
- CGO_ENABLED=0
Expand All @@ -24,14 +28,27 @@ builds:
- -X github.com/observiq/observiq-collector/internal/version.version=v{{ .Version }}
- -X github.com/observiq/observiq-collector/internal/version.gitHash={{ .FullCommit }}
- -X github.com/observiq/observiq-collector/internal/version.date={{ .Date }}
no_unique_dist_dir: true
no_unique_dist_dir: false

# https://goreleaser.com/customization/archive/
archives:
- builds:
- collector
# skip archiving as tar.gz / zip
format: binary
- format: tar.gz
name_template: "{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}"
files:
- LICENSE
- src: release_deps/opentelemetry-java-contrib-jmx-metrics.jar
dst: "."
strip_parent: true
- src: release_deps/config.yaml
dst: "."
strip_parent: true
- src: release_deps/plugins/*
dst: plugins
strip_parent: true

format_overrides:
- goos: windows
format: zip

# https://goreleaser.com/customization/checksum/
checksum:
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ ARG GITHUB_TOKEN
RUN \
make install-tools && \
goreleaser build --single-target --skip-validate --rm-dist

# Find built executable, there is only one, and copy it to working dir
RUN find /collector/dist -name observiq-collector -exec cp {} . \;

RUN curl -L \
--output /opt/opentelemetry-java-contrib-jmx-metrics.jar \
"https://github.com/open-telemetry/opentelemetry-java-contrib/releases/download/${JMX_JAR_VERSION}/opentelemetry-jmx-metrics.jar"


# Official OpenJDK has multi arch manifests for amd64 and arm64
# Java is required for JMX receiver
# Contrib's integration tests use openjdk 1.8.0
Expand All @@ -44,8 +47,8 @@ ENV PATH=$PATH:/usr/local/openjdk-8/bin
# config directory
RUN mkdir -p /etc/otel

# copy binary with unpredictable name due to dynamic GOOS / GOARCH
COPY --from=build /collector/dist/* /collector
# copy binary
COPY --from=build /collector/observiq-collector /collector/

# copy jmx receiver dependency
COPY --from=build /opt/opentelemetry-java-contrib-jmx-metrics.jar /opt/opentelemetry-java-contrib-jmx-metrics.jar
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ add-license:
echo "Add License finished successfully"; \
fi

# Downloads and setups dependencies that are packaged with binary
.PHONY: release-prep
release-prep:
@rm -rf release_deps
@mkdir release_deps
./buildscripts/download-dependencies.sh release_deps
@cp config/example.yaml release_deps/config.yaml

# Build, sign, and release
.PHONY: release
release:
Expand All @@ -153,7 +161,7 @@ release:
# Build and sign, skip release and ignore dirty git tree
.PHONY: release-test
release-test:
goreleaser release --parallelism 4 --skip-validate --skip-publish --rm-dist
goreleaser release --parallelism 4 --skip-validate --skip-publish --skip-sign --rm-dist

.PHONY: for-all
for-all:
Expand Down
10 changes: 9 additions & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ Releases are managed through GitHub releases. The steps to create a release are
- Attach binaries to the GitHub release
- Mark the release as a full release once it is finished.

4. Done! The collector is released
4. Done! The collector is released

# Testing Release locally

In order to run the `make release-test` you need to setup the following in your environment:

1. Run `make install-tools`
2. Setup a github token per [goreleaser instructions](https://goreleaser.com/scm/github/#api-token)
3. Run `make release-test`
15 changes: 10 additions & 5 deletions buildscripts/download-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@ set -e

DOWNLOAD_DIR="${1:-.}"
START_DIR=$PWD
BASEDIR="$(dirname "$(realpath "$0")")"
BASEDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PROJECT_BASE="$BASEDIR/.."
PLUGIN_VERSION="$(cat "$PROJECT_BASE/PLUGINS_VERSION")"
JAVA_CONTRIB_VERSION="$(cat "$PROJECT_BASE/JAVA_CONTRIB_VERSION")"

echo "Retrieving java contrib at $JAVA_CONTRIB_VERSION"
curl -fL -o "$DOWNLOAD_DIR/opentelemetry-java-contrib-jmx-metrics.jar" \
"https://github.com/open-telemetry/opentelemetry-java-contrib/releases/download/$(cat "$PROJECT_BASE/JAVA_CONTRIB_VERSION")/opentelemetry-jmx-metrics.jar"
"https://github.com/open-telemetry/opentelemetry-java-contrib/releases/download/$JAVA_CONTRIB_VERSION/opentelemetry-jmx-metrics.jar" > /dev/null 2>&1


echo "Retrieving stanza-plugs at commit $PLUGIN_VERSION"
if [ ! -d "$DOWNLOAD_DIR/stanza-plugins" ]; then
git clone git@github.com:observIQ/stanza-plugins.git "$DOWNLOAD_DIR/stanza-plugins"
git clone git@github.com:observIQ/stanza-plugins.git "$DOWNLOAD_DIR/stanza-plugins" > /dev/null 2>&1
fi

cd "$DOWNLOAD_DIR/stanza-plugins"
git fetch --all
git checkout "$(cat "$PROJECT_BASE/PLUGINS_VERSION")"
git fetch --all > /dev/null 2>&1
git checkout $PLUGIN_VERSION > /dev/null 2>&1
cd "$START_DIR"

cp -r "$DOWNLOAD_DIR/stanza-plugins/plugins" "$DOWNLOAD_DIR"
rm -rf "$DOWNLOAD_DIR/stanza-plugins"
2 changes: 1 addition & 1 deletion windows/scripts/build-msi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

set -e
BASEDIR="$(dirname "$(realpath "$0")")"
BASEDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PROJECT_BASE="$BASEDIR/../.."

cp "$PROJECT_BASE/dist/collector_windows_amd64.exe" "observiq-collector.exe"
Expand Down
2 changes: 1 addition & 1 deletion windows/scripts/fetch-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

set -e
BASEDIR="$(dirname "$(realpath "$0")")"
BASEDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PROJECT_BASE="$BASEDIR/../.."

[ -f go-msi.exe ] || curl -f -L -o go-msi.exe https://github.com/observIQ/go-msi/releases/download/v2.1.0/go-msi.exe
Expand Down

0 comments on commit 1bbf84a

Please sign in to comment.