Browse Source

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

Kévin Dunglas 8 months ago
parent
commit
0751f453b9
3 changed files with 42 additions and 7 deletions
  1. 21 1
      alpine.Dockerfile
  2. 4 6
      docker-bake.hcl
  3. 17 0
      static-builder.Dockerfile

+ 21 - 1
alpine.Dockerfile

@@ -1,6 +1,8 @@
 # syntax=docker/dockerfile:1
 FROM php-base AS common
 
+ARG TARGETARCH
+
 WORKDIR /app
 
 RUN apk add --no-cache \
@@ -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
 

+ 4 - 6
docker-bake.hcl

@@ -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 = "./"
@@ -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",
     ] : [
@@ -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 = "./"

+ 17 - 0
static-builder.Dockerfile

@@ -1,6 +1,8 @@
 # syntax=docker/dockerfile:1
 FROM golang-base
 
+ARG TARGETARCH
+
 ARG FRANKENPHP_VERSION=''
 ENV FRANKENPHP_VERSION=${FRANKENPHP_VERSION}
 
@@ -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