diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ac4f0a..0a690d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,20 +25,20 @@ jobs: steps: - name: Checkout git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to ghcr.io registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and Push to GHCR - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v6 with: context: . push: true @@ -58,10 +58,10 @@ jobs: steps: - name: Checkout git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to ghcr.io registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -80,10 +80,10 @@ jobs: steps: - name: Checkout git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to ghcr.io registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -104,7 +104,7 @@ jobs: output: 'results.sarif' - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v3 with: sarif_file: results.sarif category: results @@ -116,11 +116,11 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: | sameersbn/apt-cacher-ng @@ -133,18 +133,18 @@ jobs: - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to Github Packages if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -152,14 +152,14 @@ jobs: - name: Login to Quay.io if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_TOKEN }} - name: Build image and push to container registries - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v6 with: context: . push: ${{ github.event_name != 'pull_request' }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2985ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# Mac/OSX +.DS_Store + +# VIM +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Persistent undo +[._]*.un~ + +# jet brains +.idea diff --git a/Dockerfile b/Dockerfile index 4b070be..cb09c25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:jammy-20230816 +FROM ubuntu:jammy-20240808 LABEL maintainer="sameer@damagehead.com" diff --git a/README.md b/README.md index e47dda2..6a9aeee 100644 --- a/README.md +++ b/README.md @@ -136,12 +136,20 @@ Acquire::HTTP::Proxy "http://172.17.0.1:3142"; Acquire::HTTPS::Proxy "false"; ``` +If you are using a Laptop that is not always able to reach apt-proxy-ng +in order to be able detect where to use the proxy or connect direct, use the these 2 files on the Laptop +``` +cp host/01proxy /etc/apt/apt.conf.d/ +cp host/apt-proxy-detect.sh /usr/local/bin/ +``` + Similarly, to use Apt-Cacher NG in you Docker containers add the following line to your `Dockerfile` before any `apt-get` commands. ```dockerfile RUN echo 'Acquire::HTTP::Proxy "http://172.17.0.1:3142";' >> /etc/apt/apt.conf.d/01proxy \ && echo 'Acquire::HTTPS::Proxy "false";' >> /etc/apt/apt.conf.d/01proxy ``` +if you want to create your own image that has apt-cacher-ng preinstalled look at the sample config in the docker directory ## Logs diff --git a/docker-compose.yml b/docker-compose.yml index ea4b9d8..a5c7b43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,4 +8,7 @@ services: ports: - "3142:3142" volumes: - - /srv/docker/apt-cacher-ng:/var/cache/apt-cacher-ng + - apt-cacher-ng:/var/cache/apt-cacher-ng + +volumes: + apt-cacher-ng: diff --git a/docker/.env b/docker/.env new file mode 100644 index 0000000..7bdc89f --- /dev/null +++ b/docker/.env @@ -0,0 +1,3 @@ +UBUNTU_VERSION=latest +APT_CACHER_NG_IP=172.17.0.1 +APT_CACHER_NG_PORT=3142 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..7b6a057 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,11 @@ +ARG UBUNTU_VERSION=latest +FROM ubuntu:$UBUNTU_VERSION + +ARG APT_CACHER_NG_IP +ARG APT_CACHER_NG_PORT=3142 + +RUN echo "Acquire::HTTP::Proxy \"http://$APT_CACHER_NG_IP:$APT_CACHER_NG_PORT\";" > /etc/apt/apt.conf.d/01proxy \ + && echo "Acquire::HTTPS::Proxy \"false\";" >> /etc/apt/apt.conf.d/01proxy + +RUN apt-get update && \ + apt-get upgrade -y diff --git a/docker/compose.yaml b/docker/compose.yaml new file mode 100644 index 0000000..a40f3d5 --- /dev/null +++ b/docker/compose.yaml @@ -0,0 +1,11 @@ +version: '3.5' + +services: + my_server: + image: apt-cacher-ng/ubuntu:${UBUNTU_VERSION} + build: + context: . + args: + UBUNTU_VERSION: '${UBUNTU_VERSION}' + APT_CACHER_NG_IP: '${APT_CACHER_NG_IP}' + APT_CACHER_NG_PORT: '${APT_CACHER_NG_PORT}' diff --git a/host/01proxy b/host/01proxy new file mode 100644 index 0000000..d076432 --- /dev/null +++ b/host/01proxy @@ -0,0 +1,2 @@ +Acquire::HTTP::Proxy-Auto-Detect "/usr/local/bin/apt-proxy-detect.sh"; +Acquire::HTTPS::Proxy "false"; diff --git a/host/apt-proxy-detect.sh b/host/apt-proxy-detect.sh new file mode 100755 index 0000000..69b0352 --- /dev/null +++ b/host/apt-proxy-detect.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ -z $APT_CACHER_NG_IP ] +then + echo -n "DIRECT" + exit +fi + +if [ -z $APT_CACHER_NG_PORT ] +then + echo -n "DIRECT" + exit +fi + +if nc -w1 -z "$APT_CACHER_NG_IP" "$APT_CACHER_NG_PORT" 2> /dev/null +then + echo -n "http://${APT_CACHER_NG_IP}:${APT_CACHER_NG_PORT}" +else + echo -n "DIRECT" +fi