Skip to content

Commit

Permalink
Build Docker image using pre-built executables
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jul 9, 2023
1 parent ce3701f commit 2abc716
Showing 1 changed file with 58 additions and 42 deletions.
100 changes: 58 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- improve-docker-image-build
tags:
- "jq-*"
pull_request:
Expand All @@ -13,25 +14,23 @@ jobs:
fail-fast: false
matrix:
arch:
[
amd64,
arm64,
armel,
armhf,
i386,
mips,
mips64,
mips64el,
mips64r6,
mips64r6el,
mipsel,
mipsr6,
mipsr6el,
powerpc,
ppc64el,
s390x,
riscv64,
]
- amd64
- arm64
- armel
- armhf
- i386
- mips
- mips64
- mips64el
- mips64r6
- mips64r6el
- mipsel
- mipsr6
- mipsr6el
- powerpc
- ppc64el
- riscv64
- s390x
include:
- arch: amd64
CC: "x86_64-linux-gnu"
Expand Down Expand Up @@ -63,10 +62,10 @@ jobs:
CC: "powerpc-linux-gnu"
- arch: ppc64el
CC: "powerpc64le-linux-gnu"
- arch: s390x
CC: "s390x-linux-gnu"
- arch: riscv64
CC: "riscv64-linux-gnu"
- arch: s390x
CC: "s390x-linux-gnu"
runs-on: ubuntu-22.04
env:
AR: ${{ matrix.CC }}-ar
Expand Down Expand Up @@ -118,7 +117,7 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: jq-${{ env.SUFFIX }}
name: jq-linux
path: jq-${{ env.SUFFIX }}
if-no-files-found: error
retention-days: 7
Expand All @@ -128,10 +127,8 @@ jobs:
fail-fast: false
matrix:
arch:
[
amd64,
arm64,
]
- amd64
- arm64
include:
- arch: amd64
target: "x86_64-apple-darwin"
Expand All @@ -151,7 +148,7 @@ jobs:
# brew update sometimes fails with "Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!"
brew update || brew update-reset
brew install autoconf automake libtool
- name: "Set CC"
- name: Set CC
run: |
echo "CC=clang -target ${{ matrix.target }}$(uname -r)" >> $GITHUB_ENV
- name: Build
Expand Down Expand Up @@ -186,7 +183,7 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: jq-${{ env.SUFFIX }}
name: jq-macos
path: jq-${{ env.SUFFIX }}
if-no-files-found: error
retention-days: 7
Expand All @@ -196,10 +193,8 @@ jobs:
fail-fast: false
matrix:
arch:
[
amd64,
i386,
]
- amd64
- i386
include:
- arch: amd64
CC: "x86_64-pc-msys"
Expand Down Expand Up @@ -266,7 +261,7 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: jq-${{ env.SUFFIX }}
name: jq-windows
path: jq-${{ env.SUFFIX }}.exe
if-no-files-found: error
retention-days: 7
Expand Down Expand Up @@ -307,18 +302,42 @@ jobs:
runs-on: ubuntu-latest
permissions:
packages: write
if: startsWith(github.ref, 'refs/tags/jq-')
needs: linux
# if: startsWith(github.ref, 'refs/tags/jq-')
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Download executables
uses: actions/download-artifact@v3
with:
submodules: true
name: jq-linux
- name: Move executables
run: |
ls -al
mkdir -p linux/{386,amd64,arm64,mips64le,ppc64le,riscv64,s390x}
mv jq-linux-i386 linux/386/jq
mv jq-linux-amd64 linux/amd64/jq
mv jq-linux-arm64 linux/arm64/jq
mv jq-linux-mips64el linux/mips64le/jq
mv jq-linux-ppc64el linux/ppc64le/jq
mv jq-linux-riscv64 linux/riscv64/jq
mv jq-linux-s390x linux/s390x/jq
chmod +x linux/*/jq
- name: Create Dockerfile
run: |
cat <<'EOF' >Dockerfile
FROM scratch
ARG TARGETPLATFORM
COPY AUTHORS COPYING $TARGETPLATFORM/jq /
RUN ["/jq", "--version"]
ENTRYPOINT ["/jq"]
EOF
- name: Docker metadata
uses: docker/metadata-action@v4
id: metadata
with:
images: ghcr.io/${{ github.repository }}
tags: type=match,pattern=jq-(.*),group=1,value=${{ github.ref_name }}
tags: latest # type=match,pattern=jq-(.*),group=1,value=${{ github.ref_name }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand All @@ -335,7 +354,7 @@ jobs:
context: .
push: true
provenance: false
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
platforms: linux/386,linux/amd64,linux/arm64,linux/mips64le,linux/ppc64le,linux/riscv64,linux/s390x
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

Expand All @@ -355,10 +374,7 @@ jobs:
TAG_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p "release"
for files in jq-*; do
cp -rf "${files}/"* "release/"
done
mkdir -p release
mv jq-*/* release/
gh release create "$TAG_NAME" --draft --title "jq ${TAG_NAME#jq-}" --generate-notes
gh release upload "$TAG_NAME" --clobber release/jq-*

0 comments on commit 2abc716

Please sign in to comment.