From ed103f54d78fe36a26febf3d24dab72842ef6257 Mon Sep 17 00:00:00 2001 From: Yannig Date: Tue, 21 Mar 2023 06:14:20 +0100 Subject: [PATCH] :construction_worker: Update packages versions + clean up * Update packages versions + clean up * Use Oracle image to retrieve binaries * Use FQN for docker image --- Dockerfile | 24 +++++++++++++----------- Makefile | 5 +++-- alpine/Dockerfile | 12 +++++++----- go.mod | 14 ++++++-------- go.sum | 20 ++++++++------------ main.go | 33 ++++++++++++--------------------- oraclelinux/Dockerfile | 17 +++++++++-------- 7 files changed, 58 insertions(+), 67 deletions(-) diff --git a/Dockerfile b/Dockerfile index e977c90a..e78004e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19 AS build +FROM docker.io/library/golang:1.19 AS build ARG ORACLE_VERSION ENV ORACLE_VERSION=${ORACLE_VERSION} @@ -6,9 +6,10 @@ 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 && \ @@ -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é " 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 diff --git a/Makefile b/Makefile index 652aee05..40af827b 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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 diff --git a/alpine/Dockerfile b/alpine/Dockerfile index 1b5e6bd1..8301ac06 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19 AS build +FROM docker.io/library/golang:1.19 AS build ARG ORACLE_VERSION ENV ORACLE_VERSION=${ORACLE_VERSION} @@ -6,9 +6,10 @@ 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 && \ @@ -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é " @@ -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 diff --git a/go.mod b/go.mod index 1d2e73c1..5a30d6ad 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index 10751dca..bbfbee29 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/main.go b/main.go index efb597e0..44efeeee 100644 --- a/main.go +++ b/main.go @@ -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" @@ -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" ) @@ -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. @@ -52,7 +53,7 @@ const ( exporter = "exporter" ) -// Metrics object description +// Metric object description type Metric struct { Context string Labels []string @@ -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 } @@ -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 { @@ -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, @@ -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]) } @@ -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 } @@ -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 { @@ -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') diff --git a/oraclelinux/Dockerfile b/oraclelinux/Dockerfile index 5e16d659..45438b88 100644 --- a/oraclelinux/Dockerfile +++ b/oraclelinux/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19 AS build +FROM docker.io/library/golang:1.19 AS build ARG ORACLE_VERSION ENV ORACLE_VERSION=${ORACLE_VERSION} @@ -6,9 +6,10 @@ 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 && \ @@ -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