Skip to content

Commit

Permalink
use buildx/inline cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Louis Fuchs committed Dec 25, 2023
1 parent a45c18c commit 3206367
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 73 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tests

on:
push:
branches:
- main
schedule:
- cron: "0 0 * * 0"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run build
run: |
make build push
36 changes: 36 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tests

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug

- name: Build container
uses: docker/build-push-action@v5
with:
context: compose
push: false
tags: ghcr.io/adfinis/pyaptly/cache:latest
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: BUILDKIT_INLINE_CACHE=1
27 changes: 0 additions & 27 deletions .github/workflows/testing.yml

This file was deleted.

25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
.DEFAULT_GOAL := help

CACHE_IMG = "ghcr.io/adfinis/pyaptly/cache:latest"

DOCKER_BUILDKIT = 1
export DOCKER_BUILDKIT

# Help target extracts the double-hash comments from the targets and shows them
# in a convenient way. This allows us to easily document the user-facing Make
# targets
.PHONY: help
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -k 1,1 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: pull
pull: ## pull docker build cache from registry
@docker pull $(CACHE_IMG)


.PHONY: build
build: ## build image using buildx
cd compose && docker buildx build \
--cache-from type=registry,ref=ghcr.io/adfinis/pyaptly/cache:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-t ghcr.io/adfinis/pyaptly/cache:latest .


.PHONY: up
up: ## start and build container if needed
#@docker pull ghcr.io/adfinis/pyaptly/cache:latest
@DOCKER_BUILDKIT=1 docker compose up -d --build
up: build ## start the container (cached)
@docker compose up -d

.PHONY: push
push: ## push docker build cache to registry
@docker push ghcr.io/adfinis/pyaptly/cache:latest
@docker push $(CACHE_IMG)

.PHONY: down
down: ## stop and remove container
Expand Down
68 changes: 35 additions & 33 deletions compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
ARG DOCKER_IMAGE
FROM $DOCKER_IMAGE
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
python3-toml \
python3-requests \
python3-poetry \
gnupg \
bzip2 \
tini \
curl \
wait-for-it \
entr \
gnutls-bin \
nettle-dev \
gcc \
llvm-dev \
libclang-dev \
build-essential \
pkg-config \
gettext \
git \
procps \
psmisc \
vim-tiny \
cargo \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean \
&& apt-get autoclean \
&& rm -rf /var/lib/apt/archives/* \
&& rm -rf /var/cache/apt/*
ADD setup /setup
RUN /setup/setup
#RUN apt-get update && apt-get install -y --no-install-recommends \
# python3-toml \
# python3-requests \
# python3-poetry \
# gnupg \
# bzip2 \
# tini \
# curl \
# wait-for-it \
# entr \
# gnutls-bin \
# nettle-dev \
# gcc \
# llvm-dev \
# libclang-dev \
# build-essential \
# pkg-config \
# gettext \
# git \
# procps \
# psmisc \
# vim-tiny \
# cargo \
# && rm -rf /var/lib/apt/lists/* \
# && apt-get clean \
# && apt-get autoclean \
# && rm -rf /var/lib/apt/archives/* \
# && rm -rf /var/cache/apt/*
# ADD setup /setup
# RUN echo build build build build
# RUN /setup/setup
ADD run /setup/run
ENTRYPOINT ["/usr/bin/tini", "--"]
#WORKDIR /source
#ENTRYPOINT ["/usr/bin/tini", "--"]
#CMD ["bash", "/setup/run"]
1 change: 1 addition & 0 deletions compose/setup/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
9 changes: 0 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@
services:
testing:
image: ghcr.io/adfinis/pyaptly/cache:latest
build:
cache_from:
- ghcr.io/adfinis/pyaptly/cache:latest
context: compose
args:
BUILDKIT_INLINE_CACHE: 1
DOCKER_IMAGE: debian:bookworm-slim
working_dir: /source
command: ["bash", "/setup/run"]
volumes:
- ./:/source

0 comments on commit 3206367

Please sign in to comment.