Skip to content

feat: Add instance state as ENV #89

feat: Add instance state as ENV

feat: Add instance state as ENV #89

Workflow file for this run

name: Docker
on:
workflow_dispatch:
push:
# Publish `main` as Docker `edge` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: keepalived
IMAGE_TITLE: keepalived
IMAGE_DESCRIPTION: Docker container for keepalived
APP_VERSION: "2.3.1"
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
id: buildx_test
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.test-buildx-cache
key: ${{ runner.os }}-test-buildx-${{ env.APP_VERSION }}
restore-keys: |
${{ runner.os }}-test-buildx-${{ env.APP_VERSION }}
${{ runner.os }}-test-buildx-
- name: Test build
id: docker_build_test
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx_test.outputs.name }}
context: .
platforms: linux/amd64
push: false
load: true
tags: keepalived:test-build
cache-from: type=local,src=/tmp/.test-buildx-cache
cache-to: type=local,dest=/tmp/.test-buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.test-buildx-cache
mv /tmp/.test-buildx-cache-new /tmp/.test-buildx-cache
- name: Run BATS tests
run: |
docker run --rm --name keepalived-test \
--cap-add=NET_ADMIN \
--entrypoint /test/bats/bin/bats \
-w /test \
-v "$PWD/test:/test" \
keepalived:test-build .
# Build images.
build:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,enable=${{ github.ref == 'refs/heads/main' }},prefix=edge-,format=long
type=sha,enable=${{ github.ref == 'refs/heads/main' }},prefix=edge-,format=short
type=edge,branch=main
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.title=${{ env.IMAGE_TITLE }}
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.APP_VERSION }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.APP_VERSION }}
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
- name: Update README.md with latest tags
if: startsWith(github.ref, 'refs/tags')
run: |
# Build tags for README.md
echo '${{ steps.meta.outputs.json }}' | tee meta.json
README_TAGS="$(jq -r -e '.tags | map(. | sub(".+:(?<tag>.+)"; "`\(.tag)`")) | unique | reverse | join(", ")' meta.json)"
echo "Updating supported tags in readme with ${README_TAGS}"
# Replace supported latest tags in README.md
if [ -n "${README_TAGS:-}" ] && [ "${README_TAGS}" != "null" ]; then
sed -i '/- `latest`.*<!-- latest tag -->/c- '"${README_TAGS}"' <!-- latest tag -->' README.md
fi
rm -rf meta.json
- name: Update README.md with edge tags
if: startsWith(github.ref, 'refs/heads')
run: |
# Build tags for README.md
echo '${{ steps.meta.outputs.json }}' | tee meta.json
README_TAGS="$(jq -r -e '.tags | map(. | sub(".+:(?<tag>.+)"; "`\(.tag)`")) | unique | reverse | join(", ")' meta.json)"
echo "Updating supported tags in readme with ${README_TAGS}"
# Replace supported latest tags in README.md
if [ -n "${README_TAGS:-}" ] && [ "${README_TAGS}" != "null" ]; then
sed -i '/- `edge`.*<!-- edge tag -->/c- '"${README_TAGS}"' <!-- edge tag -->' README.md
fi
rm -rf meta.json
- name: Check for modified files
id: git-check
run: echo modified=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true") >> $GITHUB_OUTPUT
- name: Commit updated README.md
if: steps.git-check.outputs.modified == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m "docs(README): update supported tags [skip ci]"
git push