Skip to content

Commit

Permalink
Switch over to github.com/sijms/go-ora/v2 (#312)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
schmikei authored May 4, 2023
1 parent d0fbef9 commit f801dc4
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 194 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 41 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
69 changes: 6 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 0 additions & 8 deletions oci8.pc.template

This file was deleted.

Loading

0 comments on commit f801dc4

Please sign in to comment.