Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create a custom Go build when using musl to prevent a crash #913

Merged
merged 10 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax=docker/dockerfile:1
FROM php-base AS common

ARG TARGETARCH

WORKDIR /app

RUN apk add --no-cache \
Expand Down Expand Up @@ -64,7 +66,25 @@ RUN apk add --no-cache --virtual .build-deps \
openssl-dev \
readline-dev \
sqlite-dev \
upx
upx \
# Needed for the custom Go build
git \
bash

# FIXME: temporary workaround for https://github.com/golang/go/issues/68285
WORKDIR /
RUN git clone https://go.googlesource.com/go goroot
WORKDIR /goroot
# Revert https://github.com/golang/go/commit/3560cf0afb3c29300a6c88ccd98256949ca7a6f6 to prevent the crash with musl
RUN git config --global user.email "build@example.com" && \
git config --global user.name "Build" && \
git checkout "$(go env GOVERSION)" && \
git revert 3560cf0afb3c29300a6c88ccd98256949ca7a6f6
WORKDIR /goroot/src
ENV GOHOSTARCH="$TARGETARCH"
RUN ./make.bash
ENV PATH="/goroot/bin:$PATH"
RUN go version

WORKDIR /go/src/app

Expand Down
10 changes: 4 additions & 6 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ target "default" {
}
contexts = {
php-base = "docker-image://php:${php-version}-zts-${os}"
# FIXME: temporary workaround for https://github.com/dunglas/symfony-docker/issues/646
golang-base = "docker-image://golang:${os == "alpine" ? "1.22.4" : GO_VERSION}-${os}"
golang-base = "docker-image://golang:${GO_VERSION}-${os}"
}
dockerfile = os == "alpine" ? "alpine.Dockerfile" : "Dockerfile"
context = "./"
Expand All @@ -92,7 +91,8 @@ target "default" {
platforms = os == "alpine" ? [
"linux/amd64",
"linux/386",
"linux/arm/v6",
# FIXME: armv6 doesn't build in GitHub actions because we use a custom Go build
#"linux/arm/v6",
"linux/arm/v7",
"linux/arm64",
] : [
Expand Down Expand Up @@ -120,9 +120,7 @@ target "default" {

target "static-builder" {
contexts = {
# FIXME: temporary workaround for https://github.com/dunglas/symfony-docker/issues/646
#golang-base = "docker-image://golang:${GO_VERSION}-alpine"
golang-base = "docker-image://golang:1.22.4-alpine"
golang-base = "docker-image://golang:${GO_VERSION}-alpine"
}
dockerfile = "static-builder.Dockerfile"
context = "./"
Expand Down
17 changes: 17 additions & 0 deletions static-builder.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax=docker/dockerfile:1
FROM golang-base

ARG TARGETARCH

ARG FRANKENPHP_VERSION=''
ENV FRANKENPHP_VERSION=${FRANKENPHP_VERSION}

Expand Down Expand Up @@ -68,6 +70,21 @@ RUN apk update; \
xz ; \
ln -sf /usr/bin/php83 /usr/bin/php

# FIXME: temporary workaround for https://github.com/golang/go/issues/68285
WORKDIR /
RUN git clone https://go.googlesource.com/go goroot
WORKDIR /goroot
# Revert https://github.com/golang/go/commit/3560cf0afb3c29300a6c88ccd98256949ca7a6f6 to prevent the crash with musl
RUN git config --global user.email "build@example.com" && \
git config --global user.name "Build" && \
git checkout "$(go env GOVERSION)" && \
git revert 3560cf0afb3c29300a6c88ccd98256949ca7a6f6
WORKDIR /goroot/src
ENV GOHOSTARCH="$TARGETARCH"
RUN ./make.bash
ENV PATH="/goroot/bin:$PATH"
RUN go version

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
COPY --from=composer/composer:2-bin /composer /usr/bin/composer
Expand Down
Loading