Skip to content

Commit

Permalink
Merge pull request #3 from devilbox/release-0.3
Browse files Browse the repository at this point in the history
Release 0.3
  • Loading branch information
cytopia authored Feb 11, 2022
2 parents 7227a82 + dba1ac0 commit 9174582
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 413 deletions.
258 changes: 57 additions & 201 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ name: build
# When to run
# -------------------------------------------------------------------------------------------------
on:
# Runs on Pull Requests
pull_request:
# Runs on Push
push:


jobs:

# -----------------------------------------------------------------------------------------------
# Job: BUILD
# Job (1/2): BUILD
# -----------------------------------------------------------------------------------------------
build:
name: "[ PHP-${{ matrix.version }} (${{ matrix.arch }}) ]"
Expand All @@ -32,168 +30,79 @@ jobs:
arch:
- 'linux/amd64'
- 'linux/arm64'
- 'linux/386'
- 'linux/arm/v7'
- 'linux/arm/v6'
steps:

# ------------------------------------------------------------
# Setup repository
# ------------------------------------------------------------
- name: Checkout repository
- name: "[SETUP] Checkout repository"
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up QEMU
- name: "[SETUP] Setup QEMU environment"
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: arm64

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Set variables
id: vars
run: |
# Retrieve git info (tags, etc)
git fetch --all
# Branch, Tag or Commit
GIT_TYPE="$( \
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
| sh \
| grep '^GIT_TYPE' \
| sed 's|.*=||g' \
)"
# Branch name, Tag name or Commit Hash
GIT_SLUG="$( \
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
| sh \
| grep '^GIT_NAME' \
| sed 's|.*=||g' \
)"
# Docker Tag
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
DOCKER_TAG="latest"
else
DOCKER_TAG="${GIT_SLUG}"
fi
# Output
echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
# Export variable
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
platforms: all

- name: "[SETUP] Determine Docker tag"
id: tag
uses: cytopia/docker-tag@v0.3

# ------------------------------------------------------------
# Build
# ------------------------------------------------------------
- name: Build
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ARCH=${ARCH}
uses: cytopia/shell-command-retry-action@v0.1
with:
command: |
make build ARCH=${ARCH}
env:
ARCH: ${{ matrix.arch }}
RETRIES: 20
PAUSE: 10

# ------------------------------------------------------------
# Test
# ------------------------------------------------------------
- name: Test Docker Image
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make test ARCH=${ARCH}
- name: "[TEST] Docker Image"
uses: cytopia/shell-command-retry-action@v0.1
with:
command: |
make test ARCH=${ARCH}
env:
ARCH: ${{ matrix.arch }}
RETRIES: 20
PAUSE: 10

- name: Test Repository Readme
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make update-readme ARCH=${ARCH}
git diff --quiet || { echo "Build Changes"; git diff; git status; false; }
- name: "[TEST] Update README"
uses: cytopia/shell-command-retry-action@v0.1
with:
command: |
make update-readme ARCH=${ARCH}
env:
ARCH: ${{ matrix.arch }}
RETRIES: 20
PAUSE: 10

- name: "[TEST] Verify README"
run: |
git diff --quiet || { echo "Build Changes"; git diff; git status; false; }
# ------------------------------------------------------------
# Deploy
# ------------------------------------------------------------
- name: Publish architecture images (only repo owner)
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
# Output
echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
# Tag image
retry make tag TAG=${DOCKER_TAG}
docker images
- name: "[DEPLOY] Login"
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# Login and Push
retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }}
retry make push TAG=${DOCKER_TAG}-manifest-${ARCH##*/}
- name: "[DEPLOY] Publish architecture image (only repo owner)"
uses: cytopia/shell-command-retry-action@v0.1
with:
command: |
make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH}
env:
ARCH: ${{ matrix.arch }}
RETRIES: 20
PAUSE: 10
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
Expand All @@ -205,7 +114,7 @@ jobs:
)

# -----------------------------------------------------------------------------------------------
# Job: DEPLOY
# Job (2/2): DEPLOY
# -----------------------------------------------------------------------------------------------
deploy:
needs: [build]
Expand All @@ -221,88 +130,35 @@ jobs:
# ------------------------------------------------------------
# Setup repository
# ------------------------------------------------------------
- name: Checkout repository
- name: "[SETUP] Checkout repository"
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set variables
id: vars
run: |
# Retrieve git info (tags, etc)
git fetch --all
# Branch, Tag or Commit
GIT_TYPE="$( \
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
| sh \
| grep '^GIT_TYPE' \
| sed 's|.*=||g' \
)"
# Branch name, Tag name or Commit Hash
GIT_SLUG="$( \
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
| sh \
| grep '^GIT_NAME' \
| sed 's|.*=||g' \
)"
# Docker Tag
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
DOCKER_TAG="latest"
else
DOCKER_TAG="${GIT_SLUG}"
fi
# Output
echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
# Export variable
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
- name: "[SETUP] Determine Docker tag"
id: tag
uses: cytopia/docker-tag@v0.3

# ------------------------------------------------------------
# Deploy
# ------------------------------------------------------------
- name: Publish final multi-arch image (only repo owner)
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
# Output
echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
# Login
retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }}
- name: "[DEPLOY] Login"
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# Create manifest
docker manifest create \
devilbox/php-fpm-8.2:${DOCKER_TAG} \
--amend devilbox/php-fpm-8.2:${DOCKER_TAG}-manifest-amd64 \
--amend devilbox/php-fpm-8.2:${DOCKER_TAG}-manifest-arm64
- name: "[DEPLOY] Create Docker manifest"
uses: cytopia/shell-command-retry-action@v0.1
with:
command: |
make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6"
# Push manifest
docker manifest push devilbox/php-fpm-8.2:${DOCKER_TAG}
env:
RETRIES: 20
PAUSE: 10
- name: "[DEPLOY] Publish Docker manifest (only repo owner)"
uses: cytopia/shell-command-retry-action@v0.1
with:
command: |
make manifest-push TAG=${{ steps.tag.outputs.docker-tag }}
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
Expand Down
Loading

0 comments on commit 9174582

Please sign in to comment.