Commit 13c65f29 authored by ale's avatar ale

Simple scaffolding for self-contained Docker image

parent 47f3105a
Pipeline #2630 failed with stages
in 42 seconds
image: docker:latest
stages:
- build
- docker_build
- release
services:
- docker:dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
RELEASE_TAG: $CI_REGISTRY_IMAGE:latest
GIT_SUBMODULE_STRATEGY: recursive
build:
stage: build
image: "ai/build:stretch"
script:
- env DEBIAN_FRONTEND=noninteractive apt-get -qy install make golang-go
- make
artifacts:
paths:
- build/
docker_build:
stage: docker_build
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.git.autistici.org
- docker build --build-arg ci_token=$CI_JOB_TOKEN --pull -t $IMAGE_TAG .
- docker push $IMAGE_TAG
dependencies:
- build
release:
stage: release
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.git.autistici.org
- docker pull $IMAGE_TAG
- docker tag $IMAGE_TAG $RELEASE_TAG
- docker push $RELEASE_TAG
only:
- master
FROM golang:1 AS builder
RUN apt-get update && apt-get install -y upx
WORKDIR /build
ENV LD_FLAGS="-w"
ENV CGO_ENABLED=0
COPY go.mod go.sum /build/
RUN go mod download
RUN go mod verify
COPY . /build/
RUN echo "-- TEST" \
&& go test ./... \
&& echo "-- BUILD" \
&& go install -tags netgo -ldflags "${LD_FLAGS}" . \
&& echo "-- PACK" \
&& upx -9 /go/bin/nextcloud-exporter
FROM busybox
LABEL maintainer="Robert Jacob <xperimental@solidproject.de>"
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /go/bin/nextcloud-exporter /bin/nextcloud-exporter
USER nobody
EXPOSE 9205
ENTRYPOINT ["/bin/nextcloud-exporter"]
FROM scratch
ADD nextcloud-exporter /
CMD ["/nextcloud-exporter"]
all: nextcloud-exporter
nextcloud-exporter:
go build .
......@@ -9,7 +9,7 @@ import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/xperimental/nextcloud-exporter/serverinfo"
"git.autistici.org/ale/nextcloud-exporter/serverinfo"
)
const (
......
module github.com/xperimental/nextcloud-exporter
module git.autistici.org/ale/nextcloud-exporter
require (
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment