Skip to content

Commit

Permalink
refactor: build images from heroku/heroku:STACK-build images
Browse files Browse the repository at this point in the history
Rather than try and emulate the work heroku is doing, use their upstream images as is. This simplifies the build process signficantly, and allows us to only layer the necessary on top of their images.

This was not previously possible due to missing arm64 support, which is introduced in the heroku-24 stack. Thus, this will fail for all other stacks.
  • Loading branch information
josegonzalez committed Aug 25, 2024
1 parent d65dff8 commit 22b2e5f
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 386 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- "true"
- "false"
heroku:
- 20
- 22
- 24

steps:
Expand Down Expand Up @@ -112,8 +110,6 @@ jobs:
- buildpack-scala
- buildpack-static
heroku:
- 20
- 22
- 24

steps:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
fail-fast: false
matrix:
heroku:
- 20
- 22
- 24

steps:
Expand Down
32 changes: 10 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
ARG STACK_VERSION=20
ARG STACK_VERSION=24

FROM golang:1.23 AS builder
RUN mkdir /src
Expand All @@ -9,35 +9,22 @@ WORKDIR /src
ARG VERSION
RUN go build -a -ldflags "-X main.Version=$VERSION" -o herokuish .

FROM ubuntu:${STACK_VERSION}.04 AS base
ARG STACK_VERSION=20
FROM heroku/heroku:${STACK_VERSION}-build AS base
ARG STACK_VERSION=24
ARG TARGETARCH

ADD https://raw.githubusercontent.com/heroku/stack-images/main/heroku-${STACK_VERSION}/setup.sh /tmp/setup-01.sh
ADD https://raw.githubusercontent.com/heroku/stack-images/main/heroku-${STACK_VERSION}-build/setup.sh /tmp/setup-02.sh
COPY bin/setup.sh /tmp/setup.sh
RUN --mount=source=build-deps/${STACK_VERSION},target=/build STACK_VERSION=${STACK_VERSION} TARGETARCH=${TARGETARCH} /tmp/setup.sh && \
rm -rf /tmp/setup.sh

ENV STACK=heroku-$STACK_VERSION
ENV DEBIAN_FRONTEND noninteractive
LABEL com.gliderlabs.herokuish/stack=$STACK

RUN apt-get update -qq \
&& apt-get install --no-install-recommends -qq -y daemontools \
&& cp /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.custom \
&& apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew \
--allow-downgrades \
--allow-remove-essential \
--allow-change-held-packages \
dist-upgrade \
&& mv /etc/ImageMagick-6/policy.xml.custom /etc/ImageMagick-6/policy.xml \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /var/tmp/*

USER root
# for setuidgid
COPY bin/apt-install /usr/local/bin/apt-install
RUN apt-install daemontools
COPY --from=builder /src/herokuish /bin/

RUN /bin/herokuish buildpack install \
RUN apt-install daemontools && \
/bin/herokuish buildpack install \
&& ln -s /bin/herokuish /build \
&& ln -s /bin/herokuish /start \
&& ln -s /bin/herokuish /exec \
Expand All @@ -54,3 +41,4 @@ RUN /bin/herokuish buildpack install \
COPY include/default_user.bash /tmp/default_user.bash
RUN bash /tmp/default_user.bash && rm -f /tmp/default_user.bash
ENV BASH_BIN /usr/bin/bash
USER herokuishuser
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SHELL := /bin/bash
SYSTEM := $(shell sh -c 'uname -s 2>/dev/null')
DOCKER_ARGS ?= "--pull"
BUILDX ?= true
STACK_VERSION ?= 20
STACK_VERSION ?= 24

shellcheck:
ifneq ($(shell shellcheck --version > /dev/null 2>&1 ; echo $$?),0)
Expand Down Expand Up @@ -55,13 +55,11 @@ build: bindata.go
$(MAKE) build/deb/$(NAME)_$(VERSION)_all.deb

build/docker:
$(MAKE) build/docker/20 STACK_VERSION=20
$(MAKE) build/docker/22 STACK_VERSION=22
$(MAKE) build/docker/24 STACK_VERSION=24

build/docker/$(STACK_VERSION): bindata.go
ifeq ($(BUILDX),true)
ifeq ($(STACK_VERSION),20)
ifeq ($(STACK_VERSION),24)
docker buildx build --no-cache ${DOCKER_ARGS} --pull --progress plain --platform linux/arm64/v8,linux/amd64 --build-arg STACK_VERSION=$(STACK_VERSION) --build-arg VERSION=$(VERSION) -t $(IMAGE_NAME):$(BUILD_TAG)-$(STACK_VERSION) -t $(IMAGE_NAME):latest-$(STACK_VERSION) -t $(IMAGE_NAME):$(BUILD_TAG) -t $(IMAGE_NAME):latest .
else
docker buildx build --no-cache ${DOCKER_ARGS} --pull --progress plain --platform linux/arm64/v8,linux/amd64 --build-arg STACK_VERSION=$(STACK_VERSION) --build-arg VERSION=$(VERSION) -t $(IMAGE_NAME):$(BUILD_TAG)-$(STACK_VERSION) -t $(IMAGE_NAME):latest-$(STACK_VERSION) .
Expand Down Expand Up @@ -127,8 +125,6 @@ clean:
docker rmi herokuish:dev || true

deps: bindata.go
docker pull heroku/heroku:20-build
docker pull heroku/heroku:22-build
docker pull heroku/heroku:24-build
cd / && go get -u github.com/progrium/basht/...
$(MAKE) bindata.go
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A command line tool for emulating Heroku build and runtime tasks in containers.

Herokuish is made for platform authors. The project consolidates and decouples Heroku compatibility logic (running buildpacks, parsing Procfile) and supporting workflow (importing/exporting slugs) from specific platform images like those in Dokku/Buildstep, Deis, Flynn, etc.

The goal is to be the definitive, well maintained and heavily tested Heroku emulation utility shared by all. It is based on the [Heroku:20, Heroku:22, and Heroku:24 system images](https://github.com/heroku/stack-images). Together they form a toolkit for achieving Heroku compatibility.
The goal is to be the definitive, well maintained and heavily tested Heroku emulation utility shared by all. It is based on the [Heroku:24 system image](https://github.com/heroku/stack-images). Together they form a toolkit for achieving Heroku compatibility.

Herokuish is a community project and is in no way affiliated with Heroku.

Expand Down Expand Up @@ -208,7 +208,7 @@ $ docker run --rm -e TRACE=true -v /abs/app/path:/tmp/app gliderlabs/herokuish /
You can also set a custom buildpack:
```shell
docker run -e BUILDPACK_URL="https://github.com/custom/buildpack.git#with-a-branch" -e STACK=heroku-20 -e TRACE=true --rm -v ./:/tmp/app -it gliderlabs/herokuish /bin/herokuish test
docker run -e BUILDPACK_URL="https://github.com/custom/buildpack.git#with-a-branch" -e STACK=heroku-24 -e TRACE=true --rm -v ./:/tmp/app -it gliderlabs/herokuish /bin/herokuish test
```
Note that the underlying buildpacks will not trace their commands with `TRACE=true` is enabled. They need to independently set `set -x` in order to trace execution.
Expand Down
20 changes: 20 additions & 0 deletions bin/apt-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# apt-install - install packages using apt-get
# Usage: apt-install package1 package2 package3 ...

main() {
declare PACKAGES=("$@")

if [[ ${#PACKAGES[@]} -eq 0 ]]; then
echo "Usage: apt-install package1 package2 package3 ..."
exit 1
fi

DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -o Dpkg::Use-Pty=0 --no-install-recommends -y install "${PACKAGES[@]}"
apt-get clean
rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /var/tmp/*
}

main "$@"
58 changes: 0 additions & 58 deletions bin/setup.sh

This file was deleted.

13 changes: 0 additions & 13 deletions build-deps/20/imagemagick-policy.xml

This file was deleted.

77 changes: 0 additions & 77 deletions build-deps/20/postgresql-ACCC4CF8.asc

This file was deleted.

13 changes: 0 additions & 13 deletions build-deps/22/imagemagick-policy.xml

This file was deleted.

77 changes: 0 additions & 77 deletions build-deps/22/postgresql-ACCC4CF8.asc

This file was deleted.

Loading

0 comments on commit 22b2e5f

Please sign in to comment.