Skip to content

Commit f1d82ab

Browse files
Build scripts (#408)
* metrics exporter build scripts Signed-off-by: Anders Swanson <[email protected]>
1 parent 05fbc7d commit f1d82ab

File tree

3 files changed

+156
-2
lines changed

3 files changed

+156
-2
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ ENV TAGS=${TAGS:-godror}
1313
ARG CGO_ENABLED
1414
ENV CGO_ENABLED=${CGO_ENABLED:-1}
1515

16-
ARG GO_VERSION
17-
ENV GO_VERSION=${GO_VERSION:-1.24.9}
16+
ARG GO_VERSION=1.24.9
17+
ENV GO_VERSION=${GO_VERSION}
1818

1919
RUN microdnf install wget gzip gcc && \
2020
wget -q https://go.dev/dl/go${GO_VERSION}.${GOOS}-${GOARCH}.tar.gz && \

build-all-macos.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
# This script builds release artifacts for the Oracle Database Metrics Exporter.
4+
# You must have a working docker socket, and docker or aliased docker command.
5+
# It is designed to run on MacOS aarch64, creating the darwin-arm64 on the local host.
6+
# Artifacts for linux-arm64, linux-amd64 are built in containers.
7+
8+
# The following artifacts are created on a successful build in the 'dist' directory for the selected database driver target (godror or goora):
9+
# - linux/arm64 and linux/amd64 container images
10+
# - linux/arm64 and linux/amd64 binary tarballs for glibc 2.28 built on OL8
11+
# - linux/arm64 and linux/amd64 binary tarballs built on the latest Ubuntu distribution
12+
# - darwin-arm64 binary tarball
13+
14+
# Example usage:
15+
# ./build-all-macos.sh 2.2.0 godror
16+
17+
USAGE="Usage: $0 [-v VERSION] [-t TARGET] [-cmuo]"
18+
19+
while getopts "v:t:cmuo" opt; do
20+
case ${opt} in
21+
v ) VERSION=$OPTARG;; # Exporter version
22+
t ) TARGET=$OPTARG;; # Target database driver, may be "godror" or "goora"
23+
c ) BUILD_CONTAINERS=true;; # Build exporter containers
24+
m ) BUILD_DARWIN=true;; # Build darwin/macos binary
25+
u ) BUILD_UBUNTU=true;; # Build binaries on latest Ubuntu
26+
o ) BUILD_OL8=true;; # Build binaries on OL8
27+
\? ) echo $USAGE; exit 1;;
28+
esac
29+
done
30+
31+
if [[ -z "$VERSION" ]] || [[ -z "$TARGET" ]]; then
32+
echo $USAGE
33+
exit 1
34+
fi
35+
36+
OL_IMAGE="oraclelinux:8"
37+
BASE_IMAGE="ghcr.io/oracle/oraclelinux:8-slim"
38+
UBUNTU_IMAGE="ubuntu:24.04"
39+
OL8_GLIBC_VERSION="2.28"
40+
GO_VERSION="1.24.9"
41+
42+
if [[ "${TARGET}" == "goora" ]]; then
43+
TAGS="goora"
44+
CGO_ENABLED=0
45+
else
46+
TAGS="godror"
47+
CGO_ENABLED=1
48+
fi
49+
50+
build_darwin_local() {
51+
echo "Build dawrin-arm64"
52+
make go-build
53+
echo "Built for darwin-arm64"
54+
}
55+
56+
build_ol_platform() {
57+
build_ol "$1"
58+
rename_glibc "$1"
59+
}
60+
61+
build_ol() {
62+
local platform="$1"
63+
local container="build-${platform}"
64+
local image_artifact="exporter-${platform}"
65+
local image_tar=${image_artifact}.tar
66+
local filename="oracledb_exporter-${VERSION}.linux-${platform}.tar.gz"
67+
68+
if [[ -n "$BUILD_CONTAINERS" ]]; then
69+
echo "Starting $OL_IMAGE-${platform} build container"
70+
docker build --platform "linux/${platform}" --target=exporter-$TARGET -t $image_artifact \
71+
--build-arg GO_VERSION=$GO_VERSION --build-arg TAGS=$TAGS --build-arg CGO_ENABLED=$CGO_ENABLED \
72+
--build-arg BASE_IMAGE=$BASE_IMAGE --build-arg GOARCH=$platform --build-arg GOOS=linux --build-arg VERSION=$VERSION .
73+
fi
74+
75+
if [[ -n "BUILD_OL8" ]]; then
76+
docker run -d --privileged --platform "linux/${platform}" --name "${container}" "${OL_IMAGE}" tail -f /dev/null
77+
docker exec "${container}" bash -c "dnf install -y wget git make gcc && \
78+
wget -q https://go.dev/dl/go${GO_VERSION}.linux-${platform}.tar.gz && \
79+
rm -rf /usr/local/go && \
80+
tar -C /usr/local -xzf go${GO_VERSION}.linux-${platform}.tar.gz && \
81+
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin && \
82+
git clone --depth 1 https://github.com/oracle/oracle-db-appdev-monitoring.git && \
83+
cd oracle-db-appdev-monitoring && \
84+
make go-build TAGS=$TAGS CGO_ENABLED=$CGO_ENABLED"
85+
86+
docker cp "$container:/oracle-db-appdev-monitoring/dist/$filename" dist
87+
88+
echo "Build complete for $OL_IMAGE-${platform}"
89+
docker stop "$container"
90+
docker rm "$container"
91+
fi
92+
}
93+
94+
build_ubuntu() {
95+
local container="ubuntu-build"
96+
docker run -d --platform "linux/amd64" --name "${container}" "${UBUNTU_IMAGE}" tail -f /dev/null
97+
docker exec "${container}" bash -c "apt-get update -y && \
98+
apt-get -y install podman qemu-user-static golang gcc-aarch64-linux-gnu git make && \
99+
git clone --depth 1 https://github.com/oracle/oracle-db-appdev-monitoring.git && \
100+
cd oracle-db-appdev-monitoring && \
101+
make go-build-linux-amd64 TAGS=$TAGS CGO_ENABLED=$CGO_ENABLED && \
102+
make go-build-linux-gcc-arm64 TAGS=$TAGS CGO_ENABLED=$CGO_ENABLED"
103+
104+
105+
docker cp "$container:/oracle-db-appdev-monitoring/dist/oracledb_exporter-${VERSION}.linux-amd64.tar.gz" dist
106+
docker cp "$container:/oracle-db-appdev-monitoring/dist/oracledb_exporter-${VERSION}.linux-arm64.tar.gz" dist
107+
108+
docker stop "$container"
109+
docker rm "$container"
110+
}
111+
112+
rename_glibc() {
113+
local platform="$1"
114+
115+
local f1="oracledb_exporter-${VERSION}.linux-${platform}.tar.gz"
116+
local f2="oracledb_exporter-${VERSION}.linux-${platform}-glibc-${OL8_GLIBC_VERSION}.tar.gz"
117+
118+
mv "out/$f1" "out/$f2" 2>/dev/null
119+
}
120+
121+
# clean dist directory before build
122+
rm -r dist/* 2>/dev/null
123+
124+
# Create darwin-arm64 artifacts on local host
125+
if [[ -n "$BUILD_DARWIN" ]]; then
126+
build_darwin_local
127+
fi
128+
# Create OL8 linux artifacts and containers for glibc 2.28
129+
# OL8 Linux artifacts are built on OL8 containers
130+
build_ol_platform "arm64"
131+
build_ol_platform "amd64"
132+
133+
134+
if [[ -n "$BUILD_UBUNTU" ]]; then
135+
# Create Linux artifacts and containers
136+
build_ubuntu
137+
fi
138+

create-push-manifest.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
VERSION="$1" # Exporter version
4+
REGISTRY="$2" # Container registry/repository
5+
6+
# Tag the images
7+
docker tag exporter-amd64:latest ${REGISTRY}:${VERSION}-amd64
8+
docker tag exporter-arm64:latest ${REGISTRY}:${VERSION}-arm64
9+
10+
# Push the images
11+
docker push ${REGISTRY}:${VERSION}-amd64
12+
docker push ${REGISTRY}:${VERSION}-arm64
13+
14+
# Create and push the manifest
15+
docker manifest create ${REGISTRY}:${VERSION} ${REGISTRY}:${VERSION}-amd64 ${REGISTRY}:${VERSION}-arm64
16+
docker manifest push ${REGISTRY}:${VERSION}

0 commit comments

Comments
 (0)