Skip to content

Commit

Permalink
Merge pull request #38 from devilbox/workflow-params
Browse files Browse the repository at this point in the history
Make input more readable
  • Loading branch information
cytopia authored Mar 3, 2022
2 parents cd9cb35 + b3af9d7 commit ae4db58
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 109 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
Expand Down
3 changes: 2 additions & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name-template: '$RESOLVED_VERSION 🌈'
tag-template: '$RESOLVED_VERSION'
version-template: '$MAJOR.$MINOR'
Expand All @@ -14,7 +15,7 @@ categories:
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/action_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
# (2/2) Build
docker:
needs: [params]
uses: devilbox/github-actions/.github/workflows/docker-build-multi-arch.yml@v0.1.0
uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master
with:
enabled: true
can_deploy: true
name: ${{ needs.params.outputs.name }}
version: ${{ needs.params.outputs.matrix_version }}
arch: ${{ needs.params.outputs.matrix_arch }}
refs: ${{ needs.params.outputs.matrix_refs }}
matrix_version: ${{ needs.params.outputs.matrix_version }}
matrix_arch: ${{ needs.params.outputs.matrix_arch }}
matrix_refs: ${{ needs.params.outputs.matrix_refs }}
secrets:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
8 changes: 4 additions & 4 deletions .github/workflows/action_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
# (2/2) Build
docker:
needs: [params]
uses: devilbox/github-actions/.github/workflows/docker-build-multi-arch.yml@v0.1.0
uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master
with:
enabled: true
can_deploy: false
name: ${{ needs.params.outputs.name }}
version: ${{ needs.params.outputs.matrix_version }}
arch: ${{ needs.params.outputs.matrix_arch }}
refs: ${{ needs.params.outputs.matrix_refs }}
matrix_version: ${{ needs.params.outputs.matrix_version }}
matrix_arch: ${{ needs.params.outputs.matrix_arch }}
matrix_refs: ${{ needs.params.outputs.matrix_refs }}
secrets:
dockerhub_username: ""
dockerhub_password: ""
8 changes: 4 additions & 4 deletions .github/workflows/action_schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:
# (2/2) Build
docker:
needs: [params]
uses: devilbox/github-actions/.github/workflows/docker-build-multi-arch.yml@v0.1.0
uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master
with:
enabled: true
can_deploy: true
name: ${{ needs.params.outputs.name }}
version: ${{ needs.params.outputs.matrix_version }}
arch: ${{ needs.params.outputs.matrix_arch }}
refs: ${{ needs.params.outputs.matrix_refs }}
matrix_version: ${{ needs.params.outputs.matrix_version }}
matrix_arch: ${{ needs.params.outputs.matrix_arch }}
matrix_refs: ${{ needs.params.outputs.matrix_refs }}
secrets:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
54 changes: 35 additions & 19 deletions .github/workflows/params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
name: params


# -------------------------------------------------------------------------------------------------
# Custom Variables
# -------------------------------------------------------------------------------------------------
env:
NAME: PHP
MATRIX_VERSION: >-
[
{
"NAME": "PHP",
"VERSION": "5.2"
}
]
MATRIX_ARCH: >-
[
"linux/amd64",
"linux/386"
]
# -------------------------------------------------------------------------------------------------
# When to run
# -------------------------------------------------------------------------------------------------
Expand All @@ -25,15 +44,6 @@ on:
description: "The determined git ref matrix (only during scheduled run)"
value: ${{ jobs.params.outputs.matrix_refs }}

###
### Generic configuration
###
env:
NAME: PHP
MATRIX_VERSION: '["5.2"]'
MATRIX_ARCH: '["linux/amd64","linux/386"]'


jobs:
params:
runs-on: ubuntu-latest
Expand All @@ -45,22 +55,28 @@ jobs:
matrix_refs: ${{ steps.set-matrix-refs.outputs.matrix }}

steps:
- name: Test JSON
run: |
jq -M -c \
--argjson arches '${{ env.MATRIX_ARCH }}' \
'map({NAME:.NAME, VERSION, ARCH:$arches[]})' <<<'${{ env.MATRIX_VERSION }}'
- name: "Set Name"
id: set-name
run: |
echo '::set-output name=name::${{ env.NAME }}'
- name: "Set Matrix 'Version'"
- name: "[Set-Output] Matrix 'Version'"
id: set-matrix-version
run: |
echo '::set-output name=matrix::${{ env.MATRIX_VERSION }}'
echo "::set-output name=matrix::$( echo '${{ env.MATRIX_VERSION }}' | jq -M -c )"
- name: "Set Matrix 'Arch'"
- name: "[Set-Output] Matrix 'Arch'"
id: set-matrix-arch
run: |
echo '::set-output name=matrix::${{ env.MATRIX_ARCH }}'
echo "::set-output name=matrix::$( echo '${{ env.MATRIX_ARCH }}' | jq -M -c )"
- name: "Set Matrix 'Refs' (master branch and latest tag)"
- name: "[Set-Output] Matrix 'Refs' (master branch and latest tag)"
id: set-matrix-refs
uses: cytopia/[email protected]
with:
Expand All @@ -69,24 +85,24 @@ jobs:
num_latest_tags: 1
if: github.event_name == 'schedule'

- name: "Show settings'"
- name: "[DEBUG] Show settings'"
run: |
echo 'Name'
echo '--------------------'
echo ${{ steps.set-name.outputs.name }}
echo '${{ steps.set-name.outputs.name }}'
echo
echo 'Matrix: Version'
echo '--------------------'
echo ${{ steps.set-matrix-version.outputs.matrix }}
echo '${{ steps.set-matrix-version.outputs.matrix }}'
echo
echo 'Matrix: Arch'
echo '--------------------'
echo ${{ steps.set-matrix-arch.outputs.matrix }}
echo '${{ steps.set-matrix-arch.outputs.matrix }}'
echo
echo 'Matrix: Refs'
echo '--------------------'
echo ${{ steps.set-matrix-refs.outputs.matrix }}
echo '${{ steps.set-matrix-refs.outputs.matrix }}'
echo
1 change: 1 addition & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Release Drafter

on:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Makefile.docker
Makefile.lint
13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
extends: default

ignore: |
.yamllint


rules:
truthy:
allowed-values: ['true', 'false']
check-keys: False
level: error
line-length: disable
115 changes: 38 additions & 77 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,73 @@ ifneq (,)
.error This Makefile requires GNU Make.
endif

# Ensure additional Makefiles are present
MAKEFILES = Makefile.docker Makefile.lint
$(MAKEFILES): URL=https://raw.githubusercontent.com/devilbox/makefiles/master/$(@)
$(MAKEFILES):
@if ! (curl --fail -sS -o $(@) $(URL) || wget -O $(@) $(URL)); then \
echo "Error, curl or wget required."; \
echo "Exiting."; \
false; \
fi
include $(MAKEFILES)

# Set default Target
.DEFAULT_GOAL := help


# -------------------------------------------------------------------------------------------------
# Docker configuration
# Default configuration
# -------------------------------------------------------------------------------------------------
NAME = PHP
VERSION = 5.2
IMAGE = devilbox/php-fpm-5.2
DIR = .
FILE = Dockerfile
TAG = latest
ARCH = linux/amd64

DIR = .
FILE = Dockerfile
IMAGE = devilbox/php-fpm-5.2
TAG = latest
ARCH = linux/amd64
NO_CACHE =

FL_IGNORES = .git/,.github/,tests/,data/

# -------------------------------------------------------------------------------------------------
# Default Target
# -------------------------------------------------------------------------------------------------
.PHONY: help
help:
@echo "lint Lint project files and repository"
@echo "lint Lint project files and repository"
@echo
@echo "build Build Docker image"
@echo "rebuild Build Docker image without cache"
@echo "build [ARCH=...] [TAG=...] Build Docker image"
@echo "rebuild [ARCH=...] [TAG=...] Build Docker image without cache"
@echo "push [ARCH=...] [TAG=...] Push Docker image to Docker hub"
@echo
@echo "manifest-create Create multi-arch manifest"
@echo "manifest-push Push multi-arch manifest"
@echo "manifest-create [ARCHES=...] [TAG=...] Create multi-arch manifest"
@echo "manifest-push [TAG=...] Push multi-arch manifest"
@echo
@echo "test Test built Docker image"
@echo "update-readme Update README.md with PHP modules"
@echo "test [ARCH=...] Test built Docker image"
@echo
@echo "tag [TAG=...] Retag Docker image"
@echo "login USER=... PASS=... Login to Docker hub"
@echo "push [TAG=...] Push Docker image to Docker hub"


# -------------------------------------------------------------------------------------------------
# Lint Targets
# -------------------------------------------------------------------------------------------------
.PHONY: lint
@echo "No linting defined."


# -------------------------------------------------------------------------------------------------
# Build Targets
# Docker Targets
# -------------------------------------------------------------------------------------------------
.PHONY: build
build:
docker build --platform $(ARCH) $(NO_CACHE) -t $(IMAGE):$(TAG) -f $(DIR)/$(FILE) $(DIR)
build: docker-arch-build

.PHONY: rebuild
rebuild: NO_CACHE=--no-cache
rebuild: pull-base-image
rebuild: build
rebuild: docker-arch-rebuild

.PHONY: push
push: docker-arch-push


# -------------------------------------------------------------------------------------------------
# Manifest Targets
# -------------------------------------------------------------------------------------------------
.PHONY: manifest-create
manifest-create:
@echo "docker manifest create \
$(IMAGE):$(TAG) \
$$( echo $(ARCH) | sed 's/,/ /g' | sed 's|/|-|g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1}"' -- )" \
| sed 's/\s\s*/ /g' \
| sed 's/--/\\\n --/g'
@echo "docker manifest create \
$(IMAGE):$(TAG) \
$$( echo $(ARCH) | sed 's/,/ /g' | sed 's|/|-|g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1}"' -- )" \
| bash
manifest-create: docker-manifest-create

.PHONY: manifest-push
manifest-push:
docker manifest push $(IMAGE):$(TAG)
manifest-push: docker-manifest-push


# -------------------------------------------------------------------------------------------------
Expand All @@ -93,37 +88,3 @@ update-readme:
| perl -0 -pe "s/<!-- modules -->.*<!-- \/modules -->/<!-- modules -->\n$$(./tests/get-modules.sh $(IMAGE) $(ARCH))\n<!-- \/modules -->/s" \
> "./README.md.tmp"
yes | mv -f "./README.md.tmp" "./README.md"


# -------------------------------------------------------------------------------------------------
# Deploy Targets
# -------------------------------------------------------------------------------------------------
.PHONY: tag
tag:
docker tag $(IMAGE) $(IMAGE):$(TAG)

.PHONY: login
login:
yes | docker login --username $(USER) --password $(PASS)

.PHONY: push
push:
@$(MAKE) tag TAG=$(TAG)
docker push $(IMAGE):$(TAG)

.PHONY: push-arch
push-arch:
$(MAKE) tag TAG=$(TAG)-manifest-$(subst /,-,$(ARCH))
docker push $(IMAGE):$(TAG)-manifest-$(subst /,-,$(ARCH))


# -------------------------------------------------------------------------------------------------
# Helper Targets
# -------------------------------------------------------------------------------------------------
.PHONY: enter
enter:
docker run --rm --platform=$(ARCH) -it --entrypoint=bash $(ARG) $(IMAGE)

.PHONY: pull-base-image
pull-base-image:
@docker pull --platform $(ARCH) $(shell grep FROM Dockerfile | sed 's/^FROM\s*//g';)

0 comments on commit ae4db58

Please sign in to comment.