From f801dc432dcf07833b223887b2bd0bd99c8cbd80 Mon Sep 17 00:00:00 2001 From: Keith Schmitt <32067685+schmikei@users.noreply.github.com> Date: Thu, 4 May 2023 14:45:52 -0600 Subject: [PATCH] Switch over to github.com/sijms/go-ora/v2 (#312) * switch over to github.com/sijms/go-ora/v2 * rip stuff out of the build process (travis, rpm downloads, etc) * modify docker files to not rely on oci.pc * windows validation completed; push up multi-arch build * bump version to 0.5.0 --- .github/workflows/pull-request.yml | 34 ------------- .github/workflows/release.yml | 34 ------------- Dockerfile | 4 -- Makefile | 76 ++++++++++++++++-------------- README.md | 69 +++------------------------ alpine/Dockerfile | 6 --- go.mod | 2 +- go.sum | 4 +- main.go | 2 +- oci8.pc.template | 8 ---- oraclelinux/Dockerfile | 6 --- 11 files changed, 51 insertions(+), 194 deletions(-) delete mode 100644 oci8.pc.template diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 7999c8bf..eacecae4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -96,23 +96,6 @@ jobs: echo "oracle-version=$oracle_version" >> $GITHUB_OUTPUT echo "version=$version" >> $GITHUB_OUTPUT - - name: Setup instantclient cache - uses: actions/cache@v3 - env: - cache-name: cache-instantclient-rpm - cache-version: ${{ steps.version.outputs.oracle-version }} - with: - path: | - ./oracle-instantclient-*.rpm - ./oci8.pc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ hashFiles('**/Makefile') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}- - - - name: Install dependencies - run: | - make oci.pc prereq - - name: Setup Golang cache uses: actions/cache@v3 with: @@ -211,23 +194,6 @@ jobs: with: ref: ${{ env.PULL_REQUEST_HEAD }} - - name: Setup instantclient cache - uses: actions/cache@v3 - env: - cache-name: cache-instantclient-rpm - cache-version: ${{ needs.build.outputs.oracle-version }} - with: - path: | - ./oracle-instantclient-*.rpm - ./oci8.pc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ hashFiles('**/Makefile') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}- - - - name: Install dependencies - run: | - make oci.pc download-rpms - - name: Build image id: docker-meta env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59ea4f23..b1288be6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,23 +83,6 @@ jobs: echo "oracle-version=$oracle_version" >> $GITHUB_OUTPUT echo "version=$version" >> $GITHUB_OUTPUT - - name: Setup instantclient cache - uses: actions/cache@v3 - env: - cache-name: cache-instantclient-rpm - cache-version: ${{ steps.version.outputs.oracle-version }} - with: - path: | - ./oracle-instantclient-*.rpm - ./oci8.pc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ hashFiles('**/Makefile') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}- - - - name: Install dependencies - run: | - make oci.pc prereq - - name: Setup Golang cache uses: actions/cache@v3 with: @@ -193,23 +176,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup instantclient cache - uses: actions/cache@v3 - env: - cache-name: cache-instantclient-rpm - cache-version: ${{ needs.build.outputs.oracle-version }} - with: - path: | - ./oracle-instantclient-*.rpm - ./oci8.pc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ hashFiles('**/Makefile') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}- - - - name: Install dependencies - run: | - make oci.pc download-rpms - - name: Build image id: docker-meta env: diff --git a/Dockerfile b/Dockerfile index b28d23c0..a21028da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,6 @@ COPY --from=oracle-image /usr/lib/oracle /usr/lib/oracle COPY --from=oracle-image /usr/share/oracle /usr/share/oracle COPY --from=oracle-image /usr/include/oracle /usr/include/oracle -COPY oci8.pc.template /usr/share/pkgconfig/oci8.pc -RUN sed -i "s/@ORACLE_VERSION@/$ORACLE_VERSION/g" /usr/share/pkgconfig/oci8.pc && \ - sed -i "s/@MAJOR_VERSION@/$MAJOR_VERSION/g" /usr/share/pkgconfig/oci8.pc && \ - find /usr -name oci.pc RUN echo $LD_LIBRARY_PATH >> /etc/ld.so.conf.d/oracle.conf && ldconfig WORKDIR /go/src/oracledb_exporter diff --git a/Makefile b/Makefile index 40af827b..553b021c 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ OS_TYPE ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') ARCH_TYPE ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH))) GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) -VERSION ?= 0.4.4 +VERSION ?= 0.5.0 MAJOR_VERSION ?= 21 MINOR_VERSION ?= 8 ORACLE_VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION) @@ -12,20 +12,22 @@ PKG_VERSION ?= $(ORACLE_VERSION).0.0.0-1.el8.$(ARCH) GLIBC_VERSION ?= 2.35-r0 LDFLAGS := -X main.Version=$(VERSION) GOFLAGS := -ldflags "$(LDFLAGS) -s -w" -RPM_VERSION ?= $(ORACLE_VERSION).0.0.0-1 -ORA_RPM = oracle-instantclient-basic-$(PKG_VERSION).rpm oracle-instantclient-devel-$(PKG_VERSION).rpm -LD_LIBRARY_PATH = /usr/lib/oracle/$(ORACLE_VERSION)/client64/lib BUILD_ARGS = --build-arg VERSION=$(VERSION) --build-arg ORACLE_VERSION=$(ORACLE_VERSION) \ --build-arg MAJOR_VERSION=$(MAJOR_VERSION) --build-arg ORACLE_IMAGE=$(ORACLE_IMAGE) LEGACY_TABLESPACE = --build-arg LEGACY_TABLESPACE=.legacy-tablespace -DIST_DIR = oracledb_exporter-$(VERSION)-ora$(ORACLE_VERSION).$(OS_TYPE)-$(ARCH_TYPE) -ARCHIVE = oracledb_exporter-$(VERSION)-ora$(ORACLE_VERSION).$(OS_TYPE)-$(ARCH_TYPE).tar.gz +OUTDIR = ./dist IMAGE_NAME ?= iamseth/oracledb_exporter IMAGE_ID ?= $(IMAGE_NAME):$(VERSION) IMAGE_ID_LATEST?= $(IMAGE_NAME):latest RELEASE ?= true +ifeq ($(GOOS), windows) +EXT?=.exe +else +EXT?= +endif + export LD_LIBRARY_PATH ORACLE_VERSION version: @@ -34,30 +36,37 @@ version: oracle-version: @echo "$(ORACLE_VERSION)" -%.rpm: - wget -q "https://download.oracle.com/otn_software/linux/instantclient/$(MAJOR_VERSION)$(MINOR_VERSION)000/$@" +.PHONY: go-build +go-build: + @echo "Build $(OS_TYPE)" + mkdir -p $(OUTDIR)/oracledb_exporter-$(VERSION)-ora$(ORACLE_VERSION).$(GOOS)-$(GOARCH)/ + go build $(GOFLAGS) -o $(OUTDIR)/oracledb_exporter-$(VERSION)-ora$(ORACLE_VERSION).$(GOOS)-$(GOARCH)/oracledb_exporter$(EXT) + cp default-metrics.toml $(OUTDIR)/$(DIST_DIR) + (cd dist ; tar cfz oracledb_exporter-$(VERSION)-ora$(ORACLE_VERSION).$(GOOS)-$(GOARCH).tar.gz oracledb_exporter-$(VERSION)-ora$(ORACLE_VERSION).$(GOOS)-$(GOARCH)) -download-rpms: $(ORA_RPM) - @true +.PHONY: go-build-linux-amd64 +go-build-linux-amd64: + GOOS=linux GOARCH=amd64 $(MAKE) go-build -j2 -prereq: download-rpms - @echo deps - sudo apt-get update - sudo apt-get install --no-install-recommends -qq libaio1 rpm alien - sudo alien -i oracle*.rpm || sudo rpm -Uvh --nodeps --force oracle*.rpm - echo $(LD_LIBRARY_PATH) | sudo tee /etc/ld.so.conf.d/oracle.conf - sudo ldconfig +.PHONY: go-build-linux-arm64 +go-build-linux-arm64: + GOOS=linux GOARCH=arm64 $(MAKE) go-build -j2 -oci.pc: - sed "s/@ORACLE_VERSION@/$(ORACLE_VERSION)/g" oci8.pc.template | \ - sed "s/@MAJOR_VERSION@/$(MAJOR_VERSION)/g" > oci8.pc +.PHONY: go-build-darwin-amd64 +go-build-darwin-amd64: + GOOS=darwin GOARCH=amd64 $(MAKE) go-build -j2 -go-build: oci.pc - @echo "Build $(OS_TYPE)" - mkdir -p ./dist/$(DIST_DIR) - PKG_CONFIG_PATH=${PWD} GOOS=$(OS_TYPE) GOARCH=$(ARCH_TYPE) go build $(GOFLAGS) -o ./dist/$(DIST_DIR)/oracledb_exporter - cp default-metrics.toml ./dist/$(DIST_DIR) - (cd dist ; tar cfz $(ARCHIVE) $(DIST_DIR)) +.PHONY: go-build-darwin-arm64 +go-build-darwin-arm64: + GOOS=darwin GOARCH=arm64 $(MAKE) go-build -j2 + +.PHONY: go-build-windows-amd64 +go-build-windows-amd64: + GOOS=windows GOARCH=amd64 $(MAKE) go-build -j2 + +.PHONY: go-build-windows-x86 +go-build-windows-x86: + GOOS=windows GOARCH=386 $(MAKE) go-build -j2 go-lint: @echo "Linting codebase" @@ -70,14 +79,14 @@ build: docker @true deps: - @PKG_CONFIG_PATH=${PWD} go get + go get go-test: @echo "Run tests" - @PKG_CONFIG_PATH=${PWD} GOOS=$(OS_TYPE) GOARCH=$(ARCH_TYPE) go test -coverprofile="test-coverage.out" $$(go list ./... | grep -v /vendor/) + GOOS=$(OS_TYPE) GOARCH=$(ARCH_TYPE) go test -coverprofile="test-coverage.out" $$(go list ./... | grep -v /vendor/) clean: - rm -rf ./dist sgerrand.rsa.pub glibc-*.apk oracle-*.rpm oci8.pc + rm -rf ./dist sgerrand.rsa.pub glibc-*.apk oracle-*.rpm docker: ubuntu-image alpine-image oraclelinux-image @@ -113,7 +122,7 @@ else @echo "Can't find cosign.key file" endif -ubuntu-image: $(ORA_RPM) +ubuntu-image: if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$(IMAGE_ID)" > /dev/null; then \ echo "Image \"$(IMAGE_ID)\" already exists on ghcr.io"; \ else \ @@ -137,7 +146,7 @@ else @echo "Can't find cosign.key file" endif -alpine-image: $(ORA_RPM) +alpine-image: if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$(IMAGE_ID)-alpine" > /dev/null; then \ echo "Image \"$(IMAGE_ID)-alpine\" already exists on ghcr.io"; \ else \ @@ -159,7 +168,4 @@ else @echo "Can't find cosign.key file" endif -travis: oci.pc prereq deps go-test go-build docker - @true - -.PHONY: version build deps go-test clean docker travis glibc.apk oci.pc +.PHONY: version build deps go-test clean docker glibc.apk diff --git a/README.md b/README.md index c953221d..5feaec25 100644 --- a/README.md +++ b/README.md @@ -405,72 +405,15 @@ Or Alpine: make alpine-image -## Linux binaries +## Building Binaries -Retrieve Oracle RPMs (version x.y): +Run build: - make download-rpms - -Then run build: - - make linux - -## Windows binaries - -_Stollen from https://github.com/iamseth/oracledb_exporter/issues/40_ - -First, download Oracle Instant Client 64-Bit version basic and sdk versions. - -Extract client (for example: **C:\oracle\instantclient_18_5**) and extract SDK to the same folder (**C:\oracle\instantclient_18_5\sdk**) - -Set the environment variables: - - setx CGO_CFLAGS "C:\oracle\instantclient_18_5\sdk\include" - setx CGO_LDFLAGS "-LC:\oracle\instantclient_18_5 -loci" - -Then install GCC (like MSYS2 64 bit in **c:\msys64**) - -Run the MSYS2 MINGW64 terminal and set dependencies packages: - -- Update pacman: - - pacman -Su - -- Close terminal and open a new terminal -- Update all other packages: - - pacman -Su - -- Install pkg-config and gcc: - - pacman -S mingw64/mingw-w64-x86_64-pkg-config mingw64/mingw-w64-x86_64-gcc - -Go to the pkg-config dir **c:/msys64/mingw64/lib/pkgconfig/** and create **oci8.pc** with the following content: - - prefix=C:\oracle\instantclient_18_5/sdk/ - version=18.5 - build=client64 - libdir=C:\oracle\instantclient_18_5/sdk/lib/msvc - includedir=C:\oracle\instantclient_18_5/sdk/include - glib_genmarshal=glib-genmarshal - gobject_query=gobject-query - glib_mkenums=glib-mkenums - Name: oci8 - Description: Oracle database engine - Version: ${version} - Libs: -L${libdir} -loci - Libs.private: - Cflags: -I${includedir} - -Set **%PKG_CONFIG_PATH%** as the environment variable: - - setx PKG_CONFIG_PATH "C:\msys64\mingw64\lib\pkgconfig" - -Ensure, that **%PATH%** includes path to the msys64 binares, if not set it: setx path "%path%;C:\msys64\mingw64\bin" - -Everything must compile, including mattn driver for oracle. +```sh + make go-build +``` -Next build ./... in oracledb-exporter dir, or install it. +will output binaries and archive inside the `dist` folder for the building operating system. ## Import into your Golang Application diff --git a/alpine/Dockerfile b/alpine/Dockerfile index 4cab27cd..3aa8e4f9 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -17,12 +17,6 @@ COPY --from=oracle-image /usr/lib/oracle /usr/lib/oracle COPY --from=oracle-image /usr/share/oracle /usr/share/oracle COPY --from=oracle-image /usr/include/oracle /usr/include/oracle -COPY oci8.pc.template /usr/share/pkgconfig/oci8.pc -RUN sed -i "s/@ORACLE_VERSION@/$ORACLE_VERSION/g" /usr/share/pkgconfig/oci8.pc && \ - sed -i "s/@MAJOR_VERSION@/$MAJOR_VERSION/g" /usr/share/pkgconfig/oci8.pc && \ - find /usr -name oci.pc -RUN echo $LD_LIBRARY_PATH >> /etc/ld.so.conf.d/oracle.conf && ldconfig - WORKDIR /go/src/oracledb_exporter COPY . . RUN go get -d -v diff --git a/go.mod b/go.mod index 00939f80..f490b573 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,10 @@ require ( github.com/BurntSushi/toml v1.2.1 github.com/alecthomas/kingpin/v2 v2.3.2 github.com/go-kit/log v0.2.1 - github.com/mattn/go-oci8 v0.1.1 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/common v0.42.0 github.com/prometheus/exporter-toolkit v0.9.1 + github.com/sijms/go-ora/v2 v2.5.23 ) require ( diff --git a/go.sum b/go.sum index c7edb653..545917d1 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,6 @@ github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mattn/go-oci8 v0.1.1 h1:aEUDxNAyDG0tv8CA3TArnDQNyc4EhnWlsfxRgDHABHM= -github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= @@ -51,6 +49,8 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/sijms/go-ora/v2 v2.5.23 h1:b+TLHgbic5ry/LM99Rx4+17T5R9SEObltmpgRi0DKEk= +github.com/sijms/go-ora/v2 v2.5.23/go.mod h1:EHxlY6x7y9HAsdfumurRfTd+v8NrEOTR3Xl4FWlH6xk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= diff --git a/main.go b/main.go index cd27c61a..8921cc9a 100644 --- a/main.go +++ b/main.go @@ -6,12 +6,12 @@ import ( "os" "github.com/go-kit/log/level" - _ "github.com/mattn/go-oci8" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/version" "github.com/prometheus/exporter-toolkit/web" webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag" + _ "github.com/sijms/go-ora/v2" "github.com/alecthomas/kingpin/v2" "github.com/prometheus/common/promlog" diff --git a/oci8.pc.template b/oci8.pc.template deleted file mode 100644 index 90429ba2..00000000 --- a/oci8.pc.template +++ /dev/null @@ -1,8 +0,0 @@ -libdir=/usr/lib/oracle/@MAJOR_VERSION@/client64/lib -includedir=/usr/include/oracle/@MAJOR_VERSION@/client64 - -Name: oci8 -Description: oci8 library -Libs: -L${libdir} -lclntsh -Cflags: -I${includedir} -Version: @ORACLE_VERSION@ diff --git a/oraclelinux/Dockerfile b/oraclelinux/Dockerfile index 660fb428..5bedb1f7 100644 --- a/oraclelinux/Dockerfile +++ b/oraclelinux/Dockerfile @@ -17,12 +17,6 @@ COPY --from=oracle-image /usr/lib/oracle /usr/lib/oracle COPY --from=oracle-image /usr/share/oracle /usr/share/oracle COPY --from=oracle-image /usr/include/oracle /usr/include/oracle -COPY oci8.pc.template /usr/share/pkgconfig/oci8.pc -RUN sed -i "s/@ORACLE_VERSION@/$ORACLE_VERSION/g" /usr/share/pkgconfig/oci8.pc && \ - sed -i "s/@MAJOR_VERSION@/$MAJOR_VERSION/g" /usr/share/pkgconfig/oci8.pc && \ - find /usr -name oci.pc -RUN echo $LD_LIBRARY_PATH >> /etc/ld.so.conf.d/oracle.conf && ldconfig - WORKDIR /go/src/oracledb_exporter COPY . . RUN go get -d -v