From 589cc2fdaab2d162ea5d7aa0bcf37363d962e2a2 Mon Sep 17 00:00:00 2001 From: sneak Date: Sat, 3 Oct 2020 01:06:52 -0700 Subject: [PATCH] dockerized go-apt-cacher with config for internal use --- .drone.yml | 12 ++++++++++++ Dockerfile | 22 +++++++++++++++++++++- Makefile | 5 +++++ go-apt-cacher.toml | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .drone.yml create mode 100644 Makefile create mode 100644 go-apt-cacher.toml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..56a6b30 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,12 @@ +kind: pipeline +name: test-docker-build + +steps: +- name: test-docker-build + image: plugins/docker + settings: + repo: sneak/go-apt-cacher + dry_run: true + tags: + - ${DRONE_COMMIT_SHA} + - ${DRONE_BRANCH} diff --git a/Dockerfile b/Dockerfile index deb571f..a0f26e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,23 @@ -FROM ubuntu:focal +FROM golang:1.15-buster AS builder +WORKDIR /usr/local/src +#RUN apt update && apt install -y git +RUN git clone https://github.com/cybozu-go/aptutil.git && \ + cd aptutil && \ + git checkout 3f82d83844818cdd6a6d7dca3eca0f76d8a3fce5 + +WORKDIR /usr/local/src/aptutil +RUN go mod download +WORKDIR /usr/local/src/aptutil/cmd/go-apt-cacher +RUN go build +RUN find . + +FROM debian:buster-slim AS final +COPY --from=builder /usr/local/src/aptutil/cmd/go-apt-cacher/go-apt-cacher /usr/local/bin/go-apt-cacher +ADD ./go-apt-cacher.toml /etc/go-apt-cacher.toml +RUN chmod ugoa+rx /usr/local/bin/* && \ + mkdir -p /var/spool/go-apt-cacher && \ + chown nobody:nogroup /var/spool/go-apt-cacher +USER nobody:nogroup +ENTRYPOINT ["/usr/local/bin/go-apt-cacher"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2d19e1a --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +docker: + docker build --progress plain -t sneak/go-apt-cacher . + +run: + docker run -p 8080:8080 -ti sneak/go-apt-cacher diff --git a/go-apt-cacher.toml b/go-apt-cacher.toml new file mode 100644 index 0000000..dc985c8 --- /dev/null +++ b/go-apt-cacher.toml @@ -0,0 +1,42 @@ +# listen_address is the listening address of go-apt-cacher. +# Default is ":3142". +listen_address = ":8080" + +# Interval to check updates for Release/InRelease files. +# Default: 600 seconds +check_interval = 600 + +# Cache period for bad HTTP response statuses. +# Default: 3 seconds +cache_period = 3 + +# Directory for meta data files. +# The directory owner must be the same as the process owner of go-apt-cacher. +meta_dir = "/var/spool/go-apt-cacher/meta" + +# Directory for non-meta data files. +# This directory must be different from meta_dir. +# The directory owner must be the same as the process owner of go-apt-cacher. +cache_dir = "/var/spool/go-apt-cacher/cache" + +# Capacity for cache_dir. +# Default: 1 GiB +cache_capacity = 10 + +# Maximum concurrent connections for an upstream server. +# Setting this 0 disables limit on the number of connections. +# Default: 10 +max_conns = 20 + +# log specifies logging configurations. +# Details at https://godoc.org/github.com/cybozu-go/well#LogConfig +[log] +#filename = "/var/log/go-apt-cacher.log" +level = "info" +format = "plain" + +# mapping declares which prefix maps to a Debian repository URL. +# prefix must match this regexp: ^[a-z0-9._-]+$ +[mapping] +ubuntu = "http://archive.ubuntu.com/ubuntu" +security = "http://security.ubuntu.com/ubuntu"