├── .github └── workflows │ └── release.yml ├── Dockerfile ├── Dockerfile.tapi ├── LICENSE ├── MacOSX10.15.sdk.tar.xz ├── README.md ├── daemon.json ├── pc.sh ├── unlock-agent.sh └── upgrade-git-on-stretch.sh /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Publish Images 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | schedule: 8 | - cron: '0 0 * * 1' # Run every Monday at 12:00 AM UTC 9 | pull_request: 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | name: go ${{ matrix.tag || format( '{0}-{1}', matrix.gover, matrix.debver) }} 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | gover: 19 | - "1.23" 20 | - "1.22" 21 | - "1.21" 22 | debver: 23 | - bullseye 24 | - bookworm 25 | 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - uses: actions/checkout@v4 30 | 31 | - uses: docker/setup-buildx-action@v3 32 | 33 | - name: Login to DockerHub 34 | uses: docker/login-action@v3 35 | with: 36 | username: ${{ secrets.DOCKER_USERNAME }} 37 | password: ${{ secrets.DOCKER_PASSWORD }} 38 | 39 | - name: Build and push go ${{ matrix.tag || format( '{0}-{1}', matrix.gover, matrix.debver) }} based image 40 | uses: docker/build-push-action@v5 41 | with: 42 | push: ${{ github.ref_name == 'master' }} 43 | pull: true 44 | cache-from: type=gha 45 | cache-to: type=gha,mode=max 46 | tags: tykio/golang-cross:${{ matrix.tag || format( '{0}-{1}', matrix.gover, matrix.debver) }},tykio/golang-cross:${{ matrix.tag || format( '{0}-{1}-pgo', matrix.gover, matrix.debver) }} 47 | build-args: | 48 | GO_VERSION=${{ matrix.gover }} 49 | DEB_VERSION=${{ matrix.debver }} 50 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Committs to master will trigger a push to Dockerhub 2 | 3 | ARG GO_VERSION=1.19.12 4 | ARG DEB_VERSION=bullseye 5 | 6 | FROM golang:${GO_VERSION}-${DEB_VERSION} AS base 7 | 8 | ARG DEB_VERSION 9 | ARG DEBIAN_FRONTEND=noninteractive 10 | # Install deps 11 | RUN dpkg --add-architecture arm64 \ 12 | && dpkg --add-architecture s390x \ 13 | && apt-get update \ 14 | && apt-get dist-upgrade -y -q \ 15 | autoconf \ 16 | automake \ 17 | autotools-dev \ 18 | bc \ 19 | binfmt-support \ 20 | binutils-multiarch \ 21 | binutils-multiarch-dev \ 22 | build-essential \ 23 | clang \ 24 | git-core \ 25 | crossbuild-essential-arm64 \ 26 | crossbuild-essential-s390x \ 27 | crossbuild-essential-ppc64el \ 28 | curl \ 29 | libtool \ 30 | multistrap \ 31 | patch \ 32 | wget \ 33 | xz-utils \ 34 | lsb-release \ 35 | cmake \ 36 | apt-transport-https \ 37 | qemu-user-static \ 38 | libxml2-dev \ 39 | lzma-dev \ 40 | openssl \ 41 | libssl-dev \ 42 | unzip \ 43 | sudo \ 44 | jq \ 45 | rpm 46 | 47 | # install docker cli 48 | RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \ 49 | echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list && \ 50 | apt-get update && apt-get install -y docker-ce-cli 51 | 52 | COPY upgrade-git-on-stretch.sh / 53 | RUN /upgrade-git-on-stretch.sh ${DEB_VERSION} 54 | RUN apt-get -y autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 55 | 56 | # Used only when building locally, else the latest goreleaser is installed by GHA 57 | RUN curl -fsSL https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_Linux_x86_64.tar.gz | tar -C /usr/bin/ -xzf - goreleaser 58 | 59 | # Seems like there's an issue with buildx while running docker cli from within the container - the 60 | # experimental features are not enabled for the CLI - to mitigate that. 61 | ENV DOCKER_CLI_EXPERIMENTAL=enabled 62 | 63 | # pc.sh needs packagecloud 64 | RUN go install github.com/tyklabs/packagecloud@latest 65 | 66 | COPY unlock-agent.sh pc.sh / 67 | COPY daemon.json /etc/docker/daemon.json 68 | -------------------------------------------------------------------------------- /Dockerfile.tapi: -------------------------------------------------------------------------------- 1 | FROM golang:1.15-stretch AS base 2 | 3 | ARG APT_MIRROR 4 | RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \ 5 | && sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list 6 | ENV OSX_CROSS_PATH=/osxcross 7 | 8 | ARG DEBIAN_FRONTEND=noninteractive 9 | # Install deps 10 | RUN echo "Starting image build for $(grep PRETTY_NAME /etc/os-release)" \ 11 | && dpkg --add-architecture arm64 \ 12 | && apt-get update \ 13 | && apt-get dist-upgrade -y -q \ 14 | autoconf \ 15 | automake \ 16 | autotools-dev \ 17 | bc \ 18 | binfmt-support \ 19 | binutils-multiarch \ 20 | binutils-multiarch-dev \ 21 | build-essential \ 22 | clang \ 23 | crossbuild-essential-arm64 \ 24 | curl \ 25 | gdb \ 26 | git-core \ 27 | libtool \ 28 | multistrap \ 29 | wget \ 30 | xz-utils \ 31 | cmake \ 32 | libxml2-dev \ 33 | lzma-dev \ 34 | qemu-user-static \ 35 | openssl \ 36 | libssl-dev \ 37 | jq 38 | 39 | # FIXME: install gcc-multilib 40 | 41 | ARG OSX_SDK=MacOSX10.15.sdk 42 | WORKDIR $OSX_CROSS_PATH 43 | RUN git clone https://github.com/tpoechtrager/osxcross.git . \ 44 | && git checkout c2ad5e859d12 45 | COPY ${OSX_SDK}.tar.xz "${OSX_CROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" 46 | 47 | RUN UNATTENDED=yes OSX_VERSION_MIN=${OSX_VERSION_MIN} OCDEBUG=1 ./build.sh 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Goren G 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MacOSX10.15.sdk.tar.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TykTechnologies/golang-cross/2524c64c895b1c67840a10634e487f347b50bcc1/MacOSX10.15.sdk.tar.xz -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # golang-cross [![Actions Status](https://github.com/TykTechnologies/golang-cross/workflows/Publish%20Images/badge.svg)](https://github.com/TykTechnologies/golang-cross/actions) 2 | 3 | Forked from https://github.com/gythialy/golang-cross. 4 | 5 | Docker container to do cross compilation (Linux, windows, macOS, ARM, ARM64) of go packages including support for cgo. Upstream had some optimisations for updating just go and goreleaser that is dispensed with in this repo. 6 | 7 | `Dockerfile.tapi` is checked in that can make the process of finding the correct apple-libtapi version. As of 2023, this is a historical artefact, osx builds are no longer supported by this image. 8 | 9 | ## Local Build 10 | For example if you want to build a Go 1.16 image based on Debian buster, 11 | 12 | ``` shellsession 13 | $ docker build --build-arg GO_VERSION=1.16 --build-arg DEB_VERSION=buster -f Dockerfile -t tykio/golang-cross:1.16 . 14 | ``` 15 | 16 | ## Automation 17 | 18 | [release.yml](.github/workflows/release.yml) builds images suitable for, 19 | - OSes that do not have `GLIBC_2.23` 20 | - the standard [golang build image](https://hub.docker.com/_/golang) 21 | 22 | When creating the PR, it just builds. When committing to master, the images are pushed to . 23 | -------------------------------------------------------------------------------- /daemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "experimental": true 3 | } 4 | -------------------------------------------------------------------------------- /pc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # goreleaser calls a custom publisher for each artefact packagecloud 4 | # expects the distro version when pushing this script bridges both by 5 | # choosing the appropriate list of distro versions from $DEBVERS and 6 | # $RPMVERS 7 | # $REPO, $DEBVERS and $RPMVERS are expected to be set by the 8 | # user 9 | 10 | REQUIRED_VARS="PACKAGECLOUD_TOKEN REPO" 11 | 12 | usage() { 13 | cat <" \ 55 | --define "%__gpg /usr/bin/gpg" \ 56 | --addsign $pkg 57 | fi 58 | ;; 59 | *) 60 | echo "Unknown package, not uploading" 61 | esac 62 | 63 | for i in $vers; do 64 | 65 | [[ ! -s ${pkg} ]] && echo "File is empty or does not exists" && exit 1 66 | 67 | # Yank packages first to enable tag re-use 68 | packagecloud rm $REPO/$i $(basename $pkg) || true 69 | packagecloud push $REPO/$i $pkg 70 | 71 | done 72 | -------------------------------------------------------------------------------- /unlock-agent.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Get the GPG fingerprint with gpg --with-keygrip --list-secret-keys 4 | if [[ -z "${PKG_SIGNING_KEY}" || -z "${NFPM_STD_PASSPHRASE}" || -z "${GPG_FINGERPRINT}" ]]; then 5 | echo "No private key set, packages cannnot be signed. Set PKG_SIGNING_KEY, NFPM_STD_PASSPHRASE and GPG_FINGERPRINT" 6 | exit 1 7 | fi 8 | 9 | echo Configuring gpg-agent to accept a passphrase 10 | mkdir ~/.gnupg && chmod 700 ~/.gnupg 11 | cat > ~/.gnupg/gpg-agent.conf < ~/.gnupg/gpg.conf < tyk.io.signing.key 31 | 32 | chmod 400 tyk.io.signing.key 33 | # archive signing can work with gpg 34 | /usr/lib/gnupg2/gpg-preset-passphrase --passphrase $NFPM_STD_PASSPHRASE --preset $GPG_FINGERPRINT 35 | gpg --import --batch --yes tyk.io.signing.key || ( cat /gpg-agent.log; exit 1 ) 36 | -------------------------------------------------------------------------------- /upgrade-git-on-stretch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # git 1.18 minimum for actions/checkout@v2 4 | 5 | echo DEB_VERSION: $1 6 | 7 | if [ "$1" = "stretch" ]; then 8 | echo "deb https://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/stretch-bpo.list 9 | apt-get update 10 | apt-get install -y -t stretch-backports git 11 | fi 12 | --------------------------------------------------------------------------------