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

Split out base and toolchain and ensure CI tests the current PR #194

Merged
merged 33 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
49d1ed7
Fix yet another bug with go-gettable modules
zeripath Jan 11, 2023
e1ea0a0
Bootstrap arm-5, 6 and 7 in bootstrap-pure not build.sh
zeripath Jan 10, 2023
18b0d4d
remove golang version test in bootstrap_pure.sh as per review
zeripath Jan 11, 2023
bee7dc9
Split out base and toolchain and ensure CI tests the current PR
zeripath Jan 11, 2023
79e8734
Merge remote-tracking branch 'origin/main' into split-out-toolchain
zeripath Jan 11, 2023
4b89f5b
I do not understand why the docker build is not terminating
zeripath Jan 12, 2023
cf0c0d1
remove cache?
zeripath Jan 12, 2023
0954f40
use oci-layout
zeripath Jan 12, 2023
458811a
oci try2
zeripath Jan 12, 2023
de8f5d1
oops identifier
zeripath Jan 12, 2023
21b9cc0
try local registry
zeripath Jan 12, 2023
cb827fb
Enough the build action thing is just not helping
zeripath Jan 13, 2023
1c8d982
Update test_pr.yml
zeripath Jan 14, 2023
418748e
Update test_pr.yml
zeripath Jan 14, 2023
5f7546c
Update test_pr.yml
zeripath Jan 14, 2023
9b7bea2
Adjust spacing in docker file and add some echos
zeripath Jan 14, 2023
5643d58
whitespace
zeripath Jan 14, 2023
81848c0
try again
zeripath Jan 14, 2023
5ac47e4
rebuild xgo
zeripath Jan 14, 2023
b8baa13
this is very infuriating
zeripath Jan 14, 2023
a27dc7b
move the XGO_IN_XGO variable into the build dockerfile as it is not r…
zeripath Jan 14, 2023
3eadee4
again
zeripath Jan 14, 2023
9398808
fix build-deps.sh
zeripath Jan 14, 2023
8a0e97d
set +f to re-enable globbing
zeripath Jan 14, 2023
4a4ab6b
globs not working! not sure why
zeripath Jan 14, 2023
7efeffa
try to cache the toolchain
zeripath Jan 14, 2023
8adfeaa
reset workdir
zeripath Jan 14, 2023
12c86c2
Fix yet another bug
zeripath Jan 14, 2023
0f2e6ff
refix urls and add testcase
zeripath Jan 14, 2023
c0b42f6
Remove unused SHA arg
zeripath Jan 15, 2023
57bd52b
permit remote builds without setting GO111MODULE by assuming GO111MOD…
zeripath Jan 15, 2023
eb6ec85
reenable tests in xgo.bats
zeripath Jan 15, 2023
09b7237
Ensure default name makes sense for package built commands too
zeripath Jan 15, 2023
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
67 changes: 46 additions & 21 deletions .github/workflows/build_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,86 @@ jobs:
export VERSION=$(cat .golang_version | awk -F',' '{print $1}' | sed 's/go1/go-1/')
DOTS=$(echo -n $VERSION | awk -F"." '{print NF-1}')
if [ "$DOTS" == "1" ]; then
echo ::set-output name=value::$VERSION.0
echo ::set-output name=wildcard::$VERSION.x
echo "value=$VERSION.0" >> $GITHUB_OUTPUT
echo "wildcard=$VERSION.x" >> $GITHUB_OUTPUT
else
echo ::set-output name=value::$VERSION
echo ::set-output name=wildcard::$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')
echo "value=$VERSION" >> $GITHUB_OUTPUT
echo "wildcard=$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')" >> $GITHUB_OUTPUT
fi
id: golang_version_1
- name: get golang version 2
run: |
export VERSION=$(cat .golang_version | awk -F',' '{print $2}' | sed 's/go1/go-1/')
DOTS=$(echo -n $VERSION | awk -F"." '{print NF-1}')
if [ "$DOTS" == "1" ]; then
echo ::set-output name=value::$VERSION.0
echo ::set-output name=wildcard::$VERSION.x
echo "value=$VERSION.0" >> $GITHUB_OUTPUT
echo "wildcard=$VERSION.x" >> $GITHUB_OUTPUT
else
echo ::set-output name=value::$VERSION
echo ::set-output name=wildcard::$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')
echo "value=$VERSION" >> $GITHUB_OUTPUT
echo "wildcard=$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')" >> $GITHUB_OUTPUT
fi
id: golang_version_2
- name: get if base should be built
- name: get if toolchain should be built
run: |
export VAL=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep "docker/base" | wc -l | awk '{print $1}')
export VAL=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep "docker/toolchain" | wc -l | awk '{print $1}')
echo $VAL
echo ::set-output name=value::$(echo -n $VAL)
id: base_build
echo "value=$(echo -n $VAL)" >> $GITHUB_OUTPUT
id: toolchain_build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: build base image
- name: build toolchain image
uses: docker/build-push-action@v2
# if: steps.base_build.outputs.value != '0'
if: true
if: steps.toolchain_build.outputs.value != '0'
with:
context: docker/base/
tags: techknowlogick/xgo:base
context: docker/toolchain/
tags: techknowlogick/xgo:toolchain
push: true
file: docker/base/Dockerfile
- name: build golang ${{ steps.golang_version_1.outputs.value }} image
file: docker/toolchain/Dockerfile
- name: build golang ${{ steps.golang_version_1.outputs.value }} image base
uses: docker/build-push-action@v2
with:
context: docker/${{ steps.golang_version_1.outputs.value }}/
tags: techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }},techknowlogick/xgo:${{ steps.golang_version_1.outputs.wildcard }}
tags: techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }}-base
push: true
file: docker/${{ steps.golang_version_1.outputs.value }}/Dockerfile
build-contexts: |
toolchain=docker-image://techknowlogick/xgo:toolchain
- name: build golang ${{ steps.golang_version_1.outputs.value }} image
uses: docker/build-push-action@v3
with:
context: .
tags: techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }},techknowlogick/xgo:${{ steps.golang_version_1.outputs.wildcard }}
push: true
build-args: |
VERSION=${{ steps.golang_version_1.outputs.value }}
file: docker/build/Dockerfile
build-contexts: |
${{ steps.golang_version_1.outputs.value }}-base=docker-image://techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }}-base
- name: build golang ${{ steps.golang_version_2.outputs.value }} image
uses: docker/build-push-action@v2
with:
context: docker/${{ steps.golang_version_2.outputs.value }}/
tags: techknowlogick/xgo:${{ steps.golang_version_2.outputs.value }},techknowlogick/xgo:${{ steps.golang_version_2.outputs.wildcard }}
tags: techknowlogick/xgo:${{ steps.golang_version_2.outputs.value }}-base
push: true
file: docker/${{ steps.golang_version_2.outputs.value }}/Dockerfile
build-contexts: |
toolchain=docker-image://techknowlogick/xgo:toolchain
- name: build golang ${{ steps.golang_version_2.outputs.value }} image
uses: docker/build-push-action@v3
with:
context: .
tags: techknowlogick/xgo:${{ steps.golang_version_2.outputs.value }},techknowlogick/xgo:${{ steps.golang_version_2.outputs.wildcard }}
push: true
build-args: |
VERSION=${{ steps.golang_version_2.outputs.value }}
file: docker/build/Dockerfile
build-contexts: |
${{ steps.golang_version_2.outputs.value }}-base=docker-image://techknowlogick/xgo:${{ steps.golang_version_2.outputs.value }}-base
- name: build latest image
uses: docker/build-push-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron_generate_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python3 generate_docker_images.py

- name: Get golang version
run: echo ::set-output name=value::$(cat .golang_version)
run: echo "value=$(cat .golang_version)" >> $GITHUB_OUTPUT
id: golang_version

- name: Create Pull Request
Expand Down
95 changes: 53 additions & 42 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,75 @@ jobs:
export VERSION=$(cat .golang_version | awk -F',' '{print $1}' | sed 's/go1/go-1/')
DOTS=$(echo -n $VERSION | awk -F"." '{print NF-1}')
if [ "$DOTS" == "1" ]; then
echo ::set-output name=value::$VERSION.0
echo ::set-output name=wildcard::$VERSION.x
echo "value=$VERSION.0" >> $GITHUB_OUTPUT
echo "wildcard=$VERSION.x" >> $GITHUB_OUTPUT
else
echo ::set-output name=value::$VERSION
echo ::set-output name=wildcard::$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')
echo "value=$VERSION" >> $GITHUB_OUTPUT
echo "wildcard=$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')" >> $GITHUB_OUTPUT
fi
id: golang_version_1
- name: get golang version 2
run: |
export VERSION=$(cat .golang_version | awk -F',' '{print $2}' | sed 's/go1/go-1/')
DOTS=$(echo -n $VERSION | awk -F"." '{print NF-1}')
if [ "$DOTS" == "1" ]; then
echo ::set-output name=value::$VERSION.0
echo ::set-output name=wildcard::$VERSION.x
echo "value=$VERSION.0" >> $GITHUB_OUTPUT
echo "wildcard=$VERSION.x" >> $GITHUB_OUTPUT
else
echo ::set-output name=value::$VERSION
echo ::set-output name=wildcard::$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')
echo "value=$VERSION" >> $GITHUB_OUTPUT
echo "wildcard=$(echo -n $VERSION | sed 's/\.[^.]*$/.x/')" >> $GITHUB_OUTPUT
fi
id: golang_version_2
- name: get if base should be built
run: |
export VAL=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep "docker/base" | wc -l | awk '{print $1}')
echo $VAL
echo ::set-output name=value::$(echo -n $VAL)
id: base_build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: build base image
uses: docker/build-push-action@v2
# if: steps.base_build.outputs.value != '0'
if: true
with:
context: docker/base/
tags: techknowlogick/xgo:base
push: false
file: docker/base/Dockerfile
- name: build golang ${{ steps.golang_version_1.outputs.value }} image
uses: docker/build-push-action@v2
with:
context: docker/${{ steps.golang_version_1.outputs.value }}/
tags: techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }},techknowlogick/xgo:${{ steps.golang_version_1.outputs.wildcard }},techknowlogick/xgo:latest
push: false
file: docker/${{ steps.golang_version_1.outputs.value }}/Dockerfile
load: true
- name: build golang ${{ steps.golang_version_2.outputs.value }} image
uses: docker/build-push-action@v2
with:
context: docker/${{ steps.golang_version_2.outputs.value }}/
tags: techknowlogick/xgo:${{ steps.golang_version_2.outputs.value }},techknowlogick/xgo:${{ steps.golang_version_2.outputs.wildcard }}
push: false
file: docker/${{ steps.golang_version_2.outputs.value }}/Dockerfile
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.2.1
- name: run BATS tests
- name: cache toolchain
id: cache-toolchain
uses: actions/cache@v3
env:
cache-name: cache-toolchain
with:
path: /tmp/toolchain.tar
key: ${{ runner.os }}-toolchain-${{ hashFiles('docker/toolchain/**') }}
- if: ${{ steps.cache-toolchain.outputs.cache-hit != 'true' }}
name: build toolchain
run: |
echo "Build toolchain docker"
docker buildx build --file docker/toolchain/Dockerfile \
--tag toolchain --load docker/toolchain/
docker save -o /tmp/toolchain.tar toolchain
- name: build images and tests
run: |
echo "Load toolchain docker"
docker load -i /tmp/toolchain.tar

echo "Bootstrap go ${{ steps.golang_version_1.outputs.value }}"
docker buildx build --file docker/${{ steps.golang_version_1.outputs.value }}/Dockerfile \
--tag ${{ steps.golang_version_1.outputs.value }}-base --load docker/${{ steps.golang_version_1.outputs.value }}/

echo "Build xgo for go ${{ steps.golang_version_1.outputs.value }} "
docker buildx build --file docker/build/Dockerfile \
--tag techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }} \
--tag techknowlogick/xgo:${{ steps.golang_version_1.outputs.wildcard }} \
--tag techknowlogick/xgo:latest \
--build-arg VERSION=${{ steps.golang_version_1.outputs.value }} \
--load .

echo "Bootstrap go ${{ steps.golang_version_2.outputs.value }}"
docker buildx build --file docker/${{ steps.golang_version_2.outputs.value }}/Dockerfile \
--tag ${{ steps.golang_version_2.outputs.value }}-base --load docker/${{ steps.golang_version_2.outputs.value }}/

echo "Build xgo for go ${{ steps.golang_version_2.outputs.value }}"
docker buildx build --file docker/build/Dockerfile \
--tag techknowlogick/xgo:${{ steps.golang_version_2.outputs.value }} \
--tag techknowlogick/xgo:${{ steps.golang_version_2.outputs.wildcard }} \
--build-arg VERSION=${{ steps.golang_version_2.outputs.value }} \
--load .

mkdir -p .xgo-cache
mkdir -p ~/go/src
bats xgo.bats

echo "Run tests on latest go ${{ steps.golang_version_1.outputs.value }}"
env IMAGEID="techknowlogick/xgo:${{ steps.golang_version_1.outputs.value }}" bats xgo.bats

31 changes: 31 additions & 0 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Go cross compiler (xgo): Base cross-compilation layer
# Copyright (c) 2014 Péter Szilágyi. All rights reserved.
#
# Released under the MIT license.
ARG VERSION=latest
FROM ${VERSION}-base

LABEL maintainer="techknowlogick <[email protected]>"

COPY go.mod /xgo-src/
COPY xgo.go /xgo-src/

# Mark the image as xgo enabled to support xgo-in-xgo
ENV XGO_IN_XGO 1

# Install xgo within the container to enable internal cross compilation
WORKDIR /xgo-src
RUN \
echo "Installing xgo-in-xgo..." && \
go install xgo.go && \
ln -s /go/bin/xgo /usr/bin/xgo && \
rm -r /xgo-src

WORKDIR /

# Inject the container entry point, the build script
COPY docker/build/build.sh /build.sh
ENV BUILD /build.sh
RUN chmod +x "$BUILD"

ENTRYPOINT ["/build.sh"]
13 changes: 10 additions & 3 deletions docker/base/build.sh → docker/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,25 @@ shopt -u nullglob
# Configure some global build parameters
NAME="$OUT"


if [ "$NAME" == "" ]; then
if [[ "$USEMODULES" = true && -d /source && -f /source/go.mod ]]; then
# Go module-based builds error with 'cannot find main module'
# when $PACK is defined
NAME="$(sed -n 's/module\ \(.*\)/\1/p' /source/go.mod)"

if [[ "$NAME" != "" && "$PACK" != "" ]]; then
NAME="$NAME/$PACK"
fi
fi
fi

if [ "$NAME" == "" ]; then
if [[ "$NAME" == "" ]]; then
NAME="$(basename "$1/$PACK")"
fi

if [[ "$NAME" == "" || "$NAME" == "." ]]; then
NAME="main"
fi

# Support go module package
PACK_RELPATH="./$PACK"

Expand Down
2 changes: 1 addition & 1 deletion docker/go-1.18.10/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## GENERATED. DO NOT EDIT DIRECTLY.
FROM techknowlogick/xgo:base
FROM toolchain

ENV GO_VERSION 11810

Expand Down
2 changes: 1 addition & 1 deletion docker/go-1.18.x/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## GENERATED. DO NOT EDIT DIRECTLY.
FROM techknowlogick/xgo:go-1.18.10
FROM go-1.18.10
2 changes: 1 addition & 1 deletion docker/go-1.19.5/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## GENERATED. DO NOT EDIT DIRECTLY.
FROM techknowlogick/xgo:base
FROM toolchain

ENV GO_VERSION 1195

Expand Down
2 changes: 1 addition & 1 deletion docker/go-1.19.x/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## GENERATED. DO NOT EDIT DIRECTLY.
FROM techknowlogick/xgo:go-1.19.5
FROM go-1.19.5
Loading