Skip to content

Commit

Permalink
feat: support apt proxy (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored May 18, 2021
1 parent a0da5fe commit a564e87
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 7 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
YARN_PACKAGE_CACHE_KEY: v1
YARN_CACHE_FOLDER: .cache/yarn
NODE_VERSION: 14
APT_HTTP_PROXY: http://172.17.0.1:3142

jobs:
distro:
Expand All @@ -34,6 +35,9 @@ jobs:
steps:
- uses: actions/[email protected]

- name: start apt-cacher
run: sudo apt-get install -y apt-cacher-ng

- name: test distro
run: docker buildx bake --progress plain test

Expand Down Expand Up @@ -62,17 +66,23 @@ jobs:
latest,
]

env:
TAG: ${{ matrix.tag }}

steps:
- uses: actions/[email protected]

- name: start apt-cacher
run: sudo apt-get install -y apt-cacher-ng

- name: build
run: docker buildx bake --progress plain

- name: images
run: docker image ls

- name: test
run: docker buildx build --progress plain ./test/${{ matrix.tag }}
run: docker buildx bake --progress plain build_test

release:
needs: [lang, distro]
Expand Down Expand Up @@ -105,6 +115,9 @@ jobs:
with:
fetch-depth: 0

- name: start apt-cacher
run: sudo apt-get install -y apt-cacher-ng

- name: Docker registry login
if: github.ref == 'refs/heads/main'
run: |
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FROM ubuntu:focal@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da8

ARG USER_ID
ARG USER_NAME
ARG APT_HTTP_PROXY

LABEL maintainer="Rhys Arkins <[email protected]>" \
org.opencontainers.image.source="https://github.com/containerbase/buildpack"
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FROM ubuntu:bionic@sha256:538529c9d229fb55f50e6746b119e899775205d62c0fc1b7e679b3

ARG USER_ID
ARG USER_NAME
ARG APT_HTTP_PROXY

LABEL maintainer="Rhys Arkins <[email protected]>" \
org.opencontainers.image.source="https://github.com/containerbase/buildpack"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

This repository is the source for the Docker Hub image `containerbase/buildpack`. Commits to `main` branch are automatically built and published.

## Apt proxy

You can pass a custom temporary Apt proxy at build or runtime when installing new packages via `APT_HTTP_PROXY` arg.
All buildpack tool installer and the `install-apt` command will configure the Proxy for installation and remove it afterwards.

## Custom base image

To use a custom base image with `containerbase/buildpack` checkout [custom-base-image](./docs/custom-base-image.md) docs.
Expand Down
24 changes: 20 additions & 4 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ variable "TAG" {
default = "latest"
}

variable "APT_HTTP_PROXY" {
default = ""
}

group "default" {
targets = ["build_docker"]
}
Expand All @@ -23,14 +27,20 @@ group "test" {

target "settings" {
context = "."
args = {
APT_HTTP_PROXY = "${APT_HTTP_PROXY}"
}
}

target "cache" {
cache-from = [
"type=registry,ref=ghcr.io/${OWNER}/cache:${FILE}",
"type=registry,ref=ghcr.io/${OWNER}/cache:${FILE}-${TAG}",
]
}

target "push_cache" {
inherits = ["settings"]
inherits = ["settings", "cache"]
output = ["type=registry"]
tags = [
"ghcr.io/${OWNER}/cache:${FILE}-${TAG}",
Expand All @@ -40,7 +50,7 @@ target "push_cache" {
}

target "build_docker" {
inherits = ["settings"]
inherits = ["settings", "cache"]
output = ["type=docker"]
tags = [
"ghcr.io/${OWNER}/${FILE}",
Expand All @@ -51,14 +61,20 @@ target "build_docker" {
}

target "build_distro" {
inherits = ["settings"]
dockerfile = "Dockerfile.${TAG}"
tags = [
"${OWNER}/${FILE}:${TAG}"
]
}

target "push_ghcr" {
target "build_test" {
inherits = ["settings"]
context ="./test/${TAG}"
}

target "push_ghcr" {
inherits = ["settings", "cache"]
output = ["type=registry"]
tags = [
"ghcr.io/${OWNER}/${FILE}",
Expand All @@ -67,7 +83,7 @@ target "push_ghcr" {
}

target "push_hub" {
inherits = ["settings"]
inherits = ["settings", "cache"]
output = ["type=registry"]
tags = ["${OWNER}/${FILE}", "${OWNER}/${FILE}:${TAG}"]
}
6 changes: 6 additions & 0 deletions src/usr/local/buildpack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ function check_semver () {

function apt_install () {
echo "Installing apt packages: ${@}"
if [[ "${APT_HTTP_PROXY}" ]]; then
echo "Acquire::HTTP::Proxy \"${APT_HTTP_PROXY}\";" | tee -a /etc/apt/apt.conf.d/buildpack-proxy
echo "Acquire::HTTPS::Proxy \"DIRECT\";" | tee -a /etc/apt/apt.conf.d/buildpack-proxy
fi
apt-get update
apt-get install -y "$@"

rm -f /etc/apt/apt.conf.d/buildpack-proxy
}

function require_distro () {
Expand Down
4 changes: 4 additions & 0 deletions test/dotnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ COPY --chown=1000:0 test test
#--------------------------------------
FROM base as net3

ARG APT_HTTP_PROXY

# renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker
RUN install-tool dotnet 3.1.409

Expand Down Expand Up @@ -43,6 +45,8 @@ RUN set -ex; \
#--------------------------------------
FROM base as testb

ARG APT_HTTP_PROXY

# renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker
RUN install-tool dotnet 5.0.203

Expand Down
2 changes: 2 additions & 0 deletions test/erlang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE}

ARG APT_HTTP_PROXY

# Erlang

#disable renovate: datasource=github-releases lookupName=erlang/otp versioning=loose
Expand Down
1 change: 1 addition & 0 deletions test/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build


RUN touch /.dummy

WORKDIR /tmp
Expand Down
1 change: 0 additions & 1 deletion test/helm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build


# renovate: datasource=github-releases lookupName=helm/helm
RUN install-tool helm v3.5.4

Expand Down
4 changes: 4 additions & 0 deletions test/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build

ARG APT_HTTP_PROXY

# TODO: only lts
# renovate: datasource=docker lookupName=openjdk versioning=docker
RUN install-tool java 11.0.11
Expand Down Expand Up @@ -37,6 +39,7 @@ RUN gradle --version
#--------------------------------------
FROM build as testb

ARG APT_HTTP_PROXY

# need to stay old
RUN install-tool java 8
Expand All @@ -46,6 +49,7 @@ RUN install-tool java 8
#--------------------------------------
FROM build as testc

ARG APT_HTTP_PROXY

# renovate: datasource=docker lookupName=openjdk versioning=docker
RUN install-tool java 16.0.1
Expand Down
15 changes: 15 additions & 0 deletions test/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build

ARG APT_HTTP_PROXY

RUN touch /.dummy

# install nginx for request testing
Expand Down Expand Up @@ -55,6 +57,8 @@ RUN set -ex; \
#--------------------------------------
FROM build as testb

ARG APT_HTTP_PROXY

# renovate: datasource=github-releases depName=containerbase/python-prebuild
ARG PYTHON_VERSION=3.9.5
RUN install-tool python
Expand All @@ -67,6 +71,8 @@ RUN set -ex; \
#--------------------------------------
FROM build as testc

ARG APT_HTTP_PROXY

# renovate: datasource=docker versioning=docker
RUN install-tool node 14.17.0

Expand All @@ -78,6 +84,8 @@ RUN set -ex; \
#--------------------------------------
FROM build as testd

ARG APT_HTTP_PROXY

# renovate: datasource=github-releases lookupName=containerbase/python-prebuild
RUN install-tool php 7.4.14

Expand All @@ -90,6 +98,8 @@ RUN set -ex; \
#--------------------------------------
FROM build as teste

ARG APT_HTTP_PROXY

# Do not renovate ruby 2.x
RUN install-tool ruby 2.6.4

Expand All @@ -102,6 +112,8 @@ RUN set -ex; \
#--------------------------------------
FROM build as testf

ARG APT_HTTP_PROXY

# renovate: datasource=github-releases lookupName=PowerShell/PowerShell
RUN install-tool powershell v7.1.3

Expand All @@ -112,6 +124,9 @@ RUN set -ex; cat /etc/hosts; \
# test: terraform
#--------------------------------------
FROM build as testg

ARG APT_HTTP_PROXY

# renovate: datasource=docker lookupName=hashicorp/terraform versioning=docker
RUN install-tool terraform 0.15.3

Expand Down
2 changes: 2 additions & 0 deletions test/nix/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build

ARG APT_HTTP_PROXY

# renovate: datasource=github-releases lookupName=NixOS/nix
RUN install-tool nix 2.3.10

Expand Down
8 changes: 8 additions & 0 deletions test/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build

ARG APT_HTTP_PROXY

# renovate: datasource=docker versioning=docker
RUN install-tool node 14.17.0

Expand Down Expand Up @@ -36,6 +38,8 @@ RUN npm --version
#--------------------------------------
FROM build as testb

ARG APT_HTTP_PROXY

RUN npm install -g yarn

RUN set -ex; \
Expand Down Expand Up @@ -75,6 +79,8 @@ RUN set -ex; \

FROM build as testc

ARG APT_HTTP_PROXY

USER root

# renovate: datasource=npm
Expand All @@ -101,6 +107,8 @@ RUN set -ex; \

FROM ${IMAGE} as testd

ARG APT_HTTP_PROXY

# renovate: datasource=npm
RUN install-tool node 15.0.1

Expand Down
6 changes: 6 additions & 0 deletions test/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ COPY --chown=1000:0 test test
#--------------------------------------
FROM base as testa

ARG APT_HTTP_PROXY

# old php version, not for renovating
RUN install-tool php 7.4.14

Expand Down Expand Up @@ -48,6 +50,8 @@ RUN set -ex; \
#--------------------------------------
FROM base as testb

ARG APT_HTTP_PROXY

# old php version, not for renovating
RUN install-tool php 5.6.40

Expand Down Expand Up @@ -79,6 +83,8 @@ RUN composer --version
#--------------------------------------
FROM base as testc

ARG APT_HTTP_PROXY

# no auto env for testing
SHELL [ "/bin/sh", "-c" ]

Expand Down
2 changes: 2 additions & 0 deletions test/powershell/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build

ARG APT_HTTP_PROXY

# renovate: datasource=github-releases lookupName=PowerShell/PowerShell
RUN install-tool powershell v7.1.3

Expand Down
Loading

0 comments on commit a564e87

Please sign in to comment.