Skip to content

Commit

Permalink
👷 Update packages versions + clean up
Browse files Browse the repository at this point in the history
* Update packages versions + clean up
* Use Oracle image to retrieve binaries
* Use FQN for docker image
  • Loading branch information
Yannig authored Mar 21, 2023
1 parent 7b936b7 commit ed103f5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 67 deletions.
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM golang:1.19 AS build
FROM docker.io/library/golang:1.19 AS build

ARG ORACLE_VERSION
ENV ORACLE_VERSION=${ORACLE_VERSION}
ARG MAJOR_VERSION
ENV MAJOR_VERSION=${MAJOR_VERSION}
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${MAJOR_VERSION}/client64/lib"

RUN apt-get -qq update && apt-get install -y --no-install-recommends -qq libaio1 alien && rm -rf /var/lib/apt/lists/*
COPY oracle*${ORACLE_VERSION}*.rpm /
RUN alien -i --scripts /oracle*.rpm && rm /*.rpm
# Can't use a variable to refer to external image. So using image name
COPY --from=ghcr.io/oracle/oraclelinux8-instantclient:21 /usr/lib/oracle /usr/lib/oracle
COPY --from=ghcr.io/oracle/oraclelinux8-instantclient:21 /usr/share/oracle /usr/share/oracle
COPY --from=ghcr.io/oracle/oraclelinux8-instantclient:21 /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 && \
Expand All @@ -27,26 +28,27 @@ ENV PKG_CONFIG_PATH /go/src/oracledb_exporter

RUN GOOS=linux GOARCH=amd64 go build -v -ldflags "-X main.Version=${VERSION} -s -w"

FROM ubuntu:22.10
FROM docker.io/library/ubuntu:22.10
LABEL org.opencontainers.image.authors="Seth Miller,Yannig Perré <yannig.perre@gmail.com>"
LABEL org.opencontainers.image.description="Oracle DB Exporter"

ENV VERSION ${VERSION:-0.1.0}
ENV DEBIAN_FRONTEND=noninteractive

COPY oracle-instantclient*${ORACLE_VERSION}*basic*.rpm /

# We only need lib directory
COPY --from=build /usr/lib/oracle /usr/lib/oracle
RUN apt-get -qq update && \
apt-get -qq install -y --no-install-recommends tzdata libaio1 alien && \
alien -i --scripts /oracle*.rpm && \
rm -f /oracle*.rpm && rm -rf /var/lib/apt/lists/*
apt-get -qq install -y --no-install-recommends tzdata libaio1 && \
rm -rf /var/lib/apt/lists/*

RUN adduser --system --uid 1000 --group appuser \
&& usermod -a -G 0,appuser appuser

ARG ORACLE_VERSION
ENV ORACLE_VERSION=${ORACLE_VERSION}
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${ORACLE_VERSION}/client64/lib"
ARG MAJOR_VERSION
ENV MAJOR_VERSION=${MAJOR_VERSION}
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${MAJOR_VERSION}/client64/lib"
RUN echo $LD_LIBRARY_PATH >> /etc/ld.so.conf.d/oracle.conf && ldconfig

ARG LEGACY_TABLESPACE
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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.3
VERSION ?= 0.4.4
MAJOR_VERSION ?= 21
MINOR_VERSION ?= 8
ORACLE_VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION)
ORACLE_IMAGE ?= ghcr.io/oracle/oraclelinux8-instantclient:$(MAJOR_VERSION)
PKG_VERSION ?= $(ORACLE_VERSION).0.0.0-1.el8.$(ARCH)
GLIBC_VERSION ?= 2.35-r0
LDFLAGS := -X main.Version=$(VERSION)
Expand All @@ -15,7 +16,7 @@ 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 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
Expand Down
12 changes: 7 additions & 5 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM golang:1.19 AS build
FROM docker.io/library/golang:1.19 AS build

ARG ORACLE_VERSION
ENV ORACLE_VERSION=${ORACLE_VERSION}
ARG MAJOR_VERSION
ENV MAJOR_VERSION=${MAJOR_VERSION}
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${MAJOR_VERSION}/client64/lib"

RUN apt-get -qq update && apt-get install -y --no-install-recommends -qq libaio1 rpm && rm -rf /var/lib/apt/lists/*
COPY oracle*${ORACLE_VERSION}*.rpm /
RUN rpm -Uh --nodeps /oracle-instantclient*.x86_64.rpm && rm /*.rpm
# Can't use a variable to refer to external image. So using image name
COPY --from=ghcr.io/oracle/oraclelinux8-instantclient:21 /usr/lib/oracle /usr/lib/oracle
COPY --from=ghcr.io/oracle/oraclelinux8-instantclient:21 /usr/share/oracle /usr/share/oracle
COPY --from=ghcr.io/oracle/oraclelinux8-instantclient:21 /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 && \
Expand All @@ -27,7 +28,7 @@ ENV PKG_CONFIG_PATH /go/src/oracledb_exporter

RUN GOOS=linux GOARCH=amd64 go build -v -ldflags "-X main.Version=${VERSION} -s -w"

FROM frolvlad/alpine-glibc:glibc-2.35
FROM docker.io/frolvlad/alpine-glibc:glibc-2.35
LABEL authors="Seth Miller,Yannig Perré"
LABEL maintainer="Yannig Perré <yannig.perre@gmail.com>"

Expand All @@ -37,6 +38,7 @@ RUN apk add libaio --no-cache

ARG LEGACY_TABLESPACE
ENV LEGACY_TABLESPACE=${LEGACY_TABLESPACE}
# We only need lib directory
COPY --from=build /usr/lib/oracle /usr/lib/oracle
COPY --from=build /go/src/oracledb_exporter/oracledb_exporter /oracledb_exporter
ADD ./default-metrics${LEGACY_TABLESPACE}.toml /default-metrics.toml
Expand Down
14 changes: 6 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
module github.com/iamseth/oracledb_exporter

go 1.18
go 1.19

require (
github.com/BurntSushi/toml v1.2.1
github.com/alecthomas/kingpin/v2 v2.3.2
github.com/go-kit/kit v0.12.0
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
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

require (
github.com/alecthomas/kingpin/v2 v2.3.2 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
Expand All @@ -37,6 +35,6 @@ require (
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
20 changes: 8 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/alecthomas/kingpin/v2 v2.3.2 h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU=
github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand All @@ -19,15 +17,15 @@ github.com/go-kit/kit v0.12.0 h1:e4o3o3IsBfAKQh5Qbbiqyfu97Ku7jrO/JbohvztANh4=
github.com/go-kit/kit v0.12.0/go.mod h1:lHd+EkCZPIwYItmGDDRdhinkzX2A1sj+M9biaEaizzs=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
Expand Down Expand Up @@ -84,10 +82,8 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
33 changes: 12 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/sha256"
"database/sql"
"errors"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
"hash"
"io"
"net/http"
Expand All @@ -25,11 +27,9 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
"gopkg.in/alecthomas/kingpin.v2"
//Required for debugging
//_ "net/http/pprof"
)
Expand All @@ -44,6 +44,7 @@ var (
maxIdleConns = kingpin.Flag("database.maxIdleConns", "Number of maximum idle connections in the connection pool. (env: DATABASE_MAXIDLECONNS)").Default(getEnv("DATABASE_MAXIDLECONNS", "0")).Int()
maxOpenConns = kingpin.Flag("database.maxOpenConns", "Number of maximum open connections in the connection pool. (env: DATABASE_MAXOPENCONNS)").Default(getEnv("DATABASE_MAXOPENCONNS", "10")).Int()
scrapeInterval = kingpin.Flag("scrape.interval", "Interval between each scrape. Default is to scrape on collect requests").Default("0s").Duration()
toolkitFlags = webflag.AddFlags(kingpin.CommandLine, ":9161")
)

// Metric name parts.
Expand All @@ -52,7 +53,7 @@ const (
exporter = "exporter"
)

// Metrics object description
// Metric object description
type Metric struct {
Context string
Labels []string
Expand All @@ -64,7 +65,7 @@ type Metric struct {
IgnoreZeroResult bool
}

// Used to load multiple metrics from file
// Metrics Used to load multiple metrics from file
type Metrics struct {
Metric []Metric
}
Expand Down Expand Up @@ -96,15 +97,6 @@ func getEnv(key, fallback string) string {
return fallback
}

func atoi(stringValue string, logger log.Logger) int {
intValue, err := strconv.Atoi(stringValue)
if err != nil {
level.Error(logger).Log("msg", "error while converting to int", "err", err)
panic(err)
}
return intValue
}

func maskDsn(dsn string) string {
parts := strings.Split(dsn, "@")
if len(parts) > 1 {
Expand Down Expand Up @@ -341,7 +333,7 @@ func GetMetricType(metricType string, metricsType map[string]string) prometheus.
return valueType
}

// interface method to call ScrapeGenericValues using Metric struct values
// ScrapeMetric interface method to call ScrapeGenericValues using Metric struct values
func ScrapeMetric(db *sql.DB, ch chan<- prometheus.Metric, metricDefinition Metric, logger log.Logger) error {
level.Debug(logger).Log("msg", "Calling function ScrapeGenericValues()")
return ScrapeGenericValues(db, ch, metricDefinition.Context, metricDefinition.Labels,
Expand All @@ -350,13 +342,13 @@ func ScrapeMetric(db *sql.DB, ch chan<- prometheus.Metric, metricDefinition Metr
metricDefinition.Request, logger)
}

// generic method for retrieving metrics.
// ScrapeGenericValues generic method for retrieving metrics.
func ScrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string, labels []string,
metricsDesc map[string]string, metricsType map[string]string, metricsBuckets map[string]map[string]string, fieldToAppend string, ignoreZeroResult bool, request string, logger log.Logger) error {
metricsCount := 0
genericParser := func(row map[string]string) error {
// Construct labels value
labelsValues := []string{}
var labelsValues []string
for _, label := range labels {
labelsValues = append(labelsValues, row[label])
}
Expand All @@ -380,7 +372,7 @@ func ScrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string
if metricsType[strings.ToLower(metric)] == "histogram" {
count, err := strconv.ParseUint(strings.TrimSpace(row["count"]), 10, 64)
if err != nil {
level.Error(logger).Log("msg", "Unable to convert count value to int", "metric", metric,
level.Error(logger).Log("msg", "Unable to convert count value to int", "metric", metric,
"metricHelp", metricHelp, "value", row["count"])
continue
}
Expand Down Expand Up @@ -455,7 +447,7 @@ func ScrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string
return err
}

// inspired by https://kylewbanks.com/blog/query-result-to-map-in-golang
// GeneratePrometheusMetrics inspired by https://kylewbanks.com/blog/query-result-to-map-in-golang
// Parse SQL result and call parsing function to each row
func GeneratePrometheusMetrics(db *sql.DB, parse func(row map[string]string) error, query string, logger log.Logger) error {

Expand Down Expand Up @@ -584,9 +576,8 @@ func reloadMetrics(logger log.Logger) {

func main() {

promlogConfig := &promlog.Config{}
var promlogConfig = &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
var toolkitFlags = webflag.AddFlags(kingpin.CommandLine, ":9161")

kingpin.Version("oracledb_exporter " + Version)
kingpin.HelpFlag.Short('h')
Expand Down
17 changes: 9 additions & 8 deletions oraclelinux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM golang:1.19 AS build
FROM docker.io/library/golang:1.19 AS build

ARG ORACLE_VERSION
ENV ORACLE_VERSION=${ORACLE_VERSION}
ARG MAJOR_VERSION
ENV MAJOR_VERSION=${MAJOR_VERSION}
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${MAJOR_VERSION}/client64/lib"

RUN apt-get -qq update && apt-get install -y --no-install-recommends -qq libaio1 rpm && rm -rf /var/lib/apt/lists/*
COPY oracle*${ORACLE_VERSION}*.rpm /
RUN rpm -Uh --nodeps /oracle-instantclient*.x86_64.rpm && rm /*.rpm
ARG ORACLE_IMAGE
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 && \
Expand All @@ -27,16 +28,16 @@ ENV PKG_CONFIG_PATH /go/src/oracledb_exporter

RUN GOOS=linux GOARCH=amd64 go build -v -ldflags "-X main.Version=${VERSION} -s -w"

FROM oraclelinux:8-slim
FROM docker.io/library/oraclelinux:8-slim

ARG ORACLE_VERSION
ENV ORACLE_VERSION=${ORACLE_VERSION}
ARG MAJOR_VERSION
ENV MAJOR_VERSION=${MAJOR_VERSION}

RUN microdnf -y install oracle-release-el8 && \
microdnf -y install oracle-instantclient-release-el8 && \
microdnf -y install oracle-instantclient-basic && \
# We only need lib directory
COPY --from=build /usr/lib/oracle /usr/lib/oracle
RUN microdnf -y install libaio && \
microdnf clean all

ARG LEGACY_TABLESPACE
Expand Down

0 comments on commit ed103f5

Please sign in to comment.