Skip to content

Commit

Permalink
Fix #1 (ps. it's janky
Browse files Browse the repository at this point in the history
  • Loading branch information
egladman committed Aug 4, 2022
1 parent 020bf5c commit 25b6fbf
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 18 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/docker-publish-edge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Publish Image

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
schedule:
- cron: '45 23 * * 3'
push:
branches: [ main ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
paths-ignore:
- '**.md'

jobs:
build:

strategy:
matrix:
registry: [ghcr.io, docker.io]

include:
- registry: ghcr.io
registry_username: ${{ github.actor }}
repository: ${{ github.repository_owner }}/jq
token_secret_name: GITHUB_TOKEN

- registry: docker.io
registry_username: egladman
repository: egladman/jq
token_secret_name: DOCKERHUB_TOKEN

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 2
# https://github.com/docker/login-action
- name: Log into registry ${{ matrix.registry }}
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ matrix.registry }}
username: ${{ matrix.registry_username }}
password: ${{ secrets[matrix.token_secret_name] }}

- name: Build/Push image
run: |
make push IMG_VERSION= .BUILD_JQ_GIT_TAG=HEAD BUILDX_ENABLED=false LATEST_ENABLED=false IMG_REPOSITORY=${{ matrix.repository }} IMG_REPOSITORY_PREFIX=${{ matrix.registry }}
make push IMG_VERSION= .BUILD_JQ_GIT_TAG=HEAD BUILDX_ENABLED=false LATEST_ENABLED=false IMG_REPOSITORY=${{ matrix.repository }} IMG_REPOSITORY_PREFIX=${{ matrix.registry }} IMG_VARIANT=busybox
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN set -eux; \
automake \
bison \
busybox-static \
flex \
gcc \
git \
musl-dev \
Expand Down Expand Up @@ -62,7 +63,9 @@ RUN set -eux; \
fi; \
git clone --recursive $git_opts ${JQ_GIT_PREFIX}/jq src; \
cd src; \
if [ $(echo $JQ_VERSION | awk '{split($0,a,"."); print a[3]}') = '0' ]; then \
# Strip the trailing '.0' if passed <major>.<minor>.0
PATCH=$(echo $JQ_VERSION | awk '{split($0,a,"."); print a[3]}'); \
if [ "$PATCH" = '0' ]; then \
# The upstream project tags their releases in a wierd way :(
JQ_GIT_TAG=jq-$(echo $JQ_VERSION | awk '{split($0,a,"."); print a[1]"."a[2]}'); \
fi; \
Expand Down
39 changes: 22 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Trust me this is intentional
-include .makerc
ifeq ($(IMG_VERSION),)
EDGE_ENABLED = true
override IMG_VERSION = edge
endif
-include .makerc

DOCKER := docker
Expand All @@ -10,35 +16,34 @@ BUILDARG_PREFIX := .BUILD_

word-dot = $(word $2,$(subst ., ,$1))

# We expect IMG_VERSION to be <major>.<minor>.<patch>
IMG_VERSION_MAJOR = $(call word-dot,$(IMG_VERSION),1)
IMG_VERSION_MAJOR_MINOR := $(IMG_VERSION_MAJOR).$(call word-dot,$(IMG_VERSION),2)

ifeq ($(and $(IMG_VERSION),$(IMG_REPOSITORY),$(IMG_VARIANT)),)
$(error One or more variables are unset or empty strings. See IMG_VERSION, IMG_REPOSITORY, IMG_VARIANT)
ifeq ($(and $(IMG_REPOSITORY),$(IMG_VARIANT)),)
$(error One or more variables are unset or empty strings. See IMG_REPOSITORY, IMG_VARIANT)
endif

# Automatically use Docker buildx plugin when found
BUILDX_ENABLED := $(shell $(DOCKER) buildx version > /dev/null 2>&1 && printf true || printf false)
LATEST_ENABLED ?= true
EDGE_ENABLED ?= false

# Build images for the following platforms
IMG_PLATFORMS ?= linux/amd64 linux/arm64

IMG_VERSION_MAJOR = $(call word-dot,$(IMG_VERSION),1)
IMG_VERSION_MAJOR_MINOR := $(IMG_VERSION_MAJOR).$(call word-dot,$(IMG_VERSION),2)
GIT_SHORT_HASH := $(shell $(GIT) rev-parse --short HEAD || printf undefined)

IMG_TAGS := $(IMG_VERSION) \
$(IMG_VERSION_MAJOR) \
$(IMG_VERSION_MAJOR_MINOR) \
v$(IMG_VERSION) \
v$(IMG_VERSION_MAJOR) \
v$(IMG_VERSION_MAJOR_MINOR) \
$(IMG_VERSION)-git-$(GIT_SHORT_HASH) \
$(IMG_VERSION_MAJOR)-git-$(GIT_SHORT_HASH) \
$(IMG_VERSION_MAJOR_MINOR)-git-$(GIT_SHORT_HASH) \
v$(IMG_VERSION)-git-$(GIT_SHORT_HASH) \
v$(IMG_VERSION_MAJOR)-git-$(GIT_SHORT_HASH) \
v$(IMG_VERSION_MAJOR_MINOR)-git-$(GIT_SHORT_HASH)
$(IMG_VERSION)-git-$(GIT_SHORT_HASH)

ifeq ($(EDGE_ENABLED),false)
override IMG_TAGS += $(IMG_VERSION_MAJOR) \
$(IMG_VERSION_MAJOR_MINOR) \
v$(IMG_VERSION_MAJOR) \
v$(IMG_VERSION_MAJOR_MINOR) \
v$(IMG_VERSION)-git-$(GIT_SHORT_HASH) \
v$(IMG_VERSION_MAJOR)-git-$(GIT_SHORT_HASH) \
v$(IMG_VERSION_MAJOR_MINOR)-git-$(GIT_SHORT_HASH)
endif

ifeq ($(LATEST_ENABLED),true)
override IMG_TAGS += latest
Expand Down

0 comments on commit 25b6fbf

Please sign in to comment.