From 68bc043f11b2a334f66e17bdddb6804f6a235d5e Mon Sep 17 00:00:00 2001 From: Tobias Hargesheimer Date: Wed, 19 Jun 2024 20:58:33 +0200 Subject: [PATCH] keepalived --- .../build_docker_images-keepalived.yaml | 144 ++++++++++++++++++ keepalived.alpine.Dockerfile | 56 +++++++ keepalived.scratch.Dockerfile | 64 ++++++++ 3 files changed, 264 insertions(+) create mode 100644 .github/workflows/build_docker_images-keepalived.yaml create mode 100644 keepalived.alpine.Dockerfile create mode 100644 keepalived.scratch.Dockerfile diff --git a/.github/workflows/build_docker_images-keepalived.yaml b/.github/workflows/build_docker_images-keepalived.yaml new file mode 100644 index 0000000..6e08578 --- /dev/null +++ b/.github/workflows/build_docker_images-keepalived.yaml @@ -0,0 +1,144 @@ +name: 'build docker images: keepalived' + +on: + #push: + # branches: + # - 'main' + # - 'master' + # paths: + # - 'keepalived.scratch.Dockerfile' + # - '.github/workflows/build_docker_images-keepalived.yaml' + workflow_dispatch: + schedule: + - cron: '45 3 11 * *' # At 03:45 on day-of-month 11. + +defaults: + run: + shell: bash + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Shell-Script + id: script + run: | + BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + BUILD_DATE_NUMERIC="${BUILD_DATE//[^[:digit:]]/}" + COMMIT_HASH=${GITHUB_SHA::8} + GIT_URL=$(echo "${GITHUB_SERVER_URL}" | awk -F/ '{print $3}' | sed 's/\/*$//') + GIT_URL=$(echo "$GIT_URL" | sed 's/github\.com/ghcr\.io/g') # GIT_URL switch to ghcr.io registry for GitHub + GIT_REPO=${GITHUB_REPOSITORY,,} + GIT_REPO_SHORT=${GIT_REPO#*/} + GIT_REPO_SHORT=${GIT_REPO_SHORT#"docker-"} + DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GIT_REPO_SHORT} + REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GIT_REPO_SHORT} + + echo "ENVs: BUILD_DATE=${BUILD_DATE}, BUILD_DATE_NUMERIC=${BUILD_DATE_NUMERIC}, COMMIT_HASH=${COMMIT_HASH}, GIT_URL=${GIT_URL}, GIT_REPO=${GIT_REPO}" + #echo "ENVs (by Git) for Owner: GITHUB_REPOSITORY_OWNER=${GITHUB_REPOSITORY_OWNER} and github.repository_owner=${{ github.repository_owner }} are the same!" + + # Keepalived + KEEPALIVED_VERSION=$(wget -qO- https://api.github.com/repos/acassen/keepalived/tags | grep 'name' | cut -d\" -f4 | head -1 ) + echo "KEEPALIVED_VERSION=${KEEPALIVED_VERSION}" + + # Set output parameters to action. + echo "build_date=${BUILD_DATE}" >> "$GITHUB_OUTPUT" + echo "build_date_numeric=${BUILD_DATE_NUMERIC}" >> "$GITHUB_OUTPUT" + echo "commit_hash=${COMMIT_HASH}" >> "$GITHUB_OUTPUT" + echo "git_url=${GIT_URL}" >> "$GITHUB_OUTPUT" + echo "git_repo=${GIT_REPO}" >> "$GITHUB_OUTPUT" + echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT" + echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT" + echo "keepalived_version=${KEEPALIVED_VERSION}" >> "$GITHUB_OUTPUT" + + # TOKEN workarround for Gitea/Forgejo + if [[ $GIT_URL == "github.com" || $GIT_URL == "ghcr.io" ]]; then GIT_REGISTRY_TOKEN="${{ secrets.GITHUB_TOKEN }}"; else GIT_REGISTRY_TOKEN="${{ secrets.GIT_USER_PASSWD }}"; fi + echo "git_registry_token=${GIT_REGISTRY_TOKEN}" >> "$GITHUB_OUTPUT" + # add "GIT_USER_PASSWD" to Settings->Actions->Secrets in Repository, + # because ${{ secrets.GITHUB_TOKEN }}, ${GITHUB_TOKEN}, ${{ github.token }} or ${{ env.GITHUB_TOKEN }} not working :-( + # see: https://github.com/go-gitea/gitea/issues/23642 for ${{ secrets.GITEA_TOKEN}} and other. + + #- name: Shell-Script-echo-outputs + # id: script-echo + # run: | + # echo ${{steps.script.outputs.build_date}} + # echo ${{steps.script.outputs.build_date_numeric}} + # echo ${{steps.script.outputs.commit_hash}} + # echo ${{steps.script.outputs.git_url}} + # echo ${{steps.script.outputs.git_repo}} + # echo ${{steps.script.outputs.docker_repo}} + + - name: Install Docker + run: | + if ! command -v docker &> /dev/null; then + curl -fsSL https://get.docker.com | sh + else + echo "skip -> Docker is already installed!" + fi + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + with: + config-inline: | + [registry."${{steps.script.outputs.git_url}}"] + #insecure = true + ca=["/etc/ssl/certs/ca-certificates.crt"] + + - name: Login to GIT Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ steps.script.outputs.git_url }} + username: ${{ github.repository_owner }} + password: ${{ steps.script.outputs.git_registry_token }} # ${{ secrets.GITHUB_TOKEN }} + + - name: Login to DockerHub Container Registry + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to RED HAT Quay.io Container Registry + uses: docker/login-action@v1 + with: + registry: quay.io + username: ${{ secrets.REDHAT_QUAY_USERNAME }} + password: ${{ secrets.REDHAT_QUAY_PASSWORD }} + + - name: Build + uses: docker/build-push-action@v5 + with: + builder: ${{ steps.buildx.outputs.name }} + context: . + file: ./keepalived.scratch.Dockerfile + platforms: linux/amd64,linux/arm64/v8,linux/arm/v7 + push: true + build-args: | + BUILD_DATE=${{steps.script.outputs.build_date}} + VCS_REF=${{steps.script.outputs.commit_hash}} + VERSION=${{steps.script.outputs.keepalived_version}} + tags: | + ${{steps.script.outputs.git_url}}/${{steps.script.outputs.git_repo}}:keepalived + docker.io/${{steps.script.outputs.docker_repo}}:keepalived + docker.io/${{steps.script.outputs.docker_repo}}:keepalived-${{steps.script.outputs.keepalived_version}} + quay.io/${{steps.script.outputs.redhat_quay_repo}}:keepalived + + #- name: Docker Hub Description + # uses: peter-evans/dockerhub-description@v3 + # with: + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + # repository: ${{steps.script.outputs.docker_repo}} + # short-description: ${{ github.event.repository.description }} + # readme-filepath: README.md \ No newline at end of file diff --git a/keepalived.alpine.Dockerfile b/keepalived.alpine.Dockerfile new file mode 100644 index 0000000..6aa8598 --- /dev/null +++ b/keepalived.alpine.Dockerfile @@ -0,0 +1,56 @@ +# docker build --no-cache --progress=plain --build-arg VERSION=v2.3.1 -t tobi312/tools:keepalived-alpine -f keepalived.alpine.Dockerfile . +FROM alpine:latest + +ARG VERSION + +ARG VCS_REF +ARG BUILD_DATE + +LABEL org.opencontainers.image.title="Keepalived" \ + org.opencontainers.image.authors="Alexandre Cassen , Tobias Hargesheimer " \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.revision="${VCS_REF}" \ + org.opencontainers.image.description="Keepalived is a routing software written in C" \ + org.opencontainers.image.documentation="https://keepalived.org/manpage.html , https://github.com/acassen/keepalived" \ + org.opencontainers.image.base.name="docker.io/library/alpine:latest" \ + org.opencontainers.image.licenses="GPL-2.0" \ + org.opencontainers.image.url="https://hub.docker.com/r/tobi312/tools" \ + org.opencontainers.image.source="https://github.com/Tob1as/docker-tools" + +RUN \ + apk add --no-cache --virtual .build-deps \ + autoconf \ + automake \ + binutils \ + gcc \ + libnl3-dev \ + #libnftnl-dev \ + #libmnl-dev \ + linux-headers \ + make \ + musl-dev \ + openssl-dev \ + \ + git \ + ; \ + apk add --no-cache \ + musl \ + libnl3 \ + ; \ + VERSION=${VERSION:-$(wget -qO- https://api.github.com/repos/acassen/keepalived/tags | grep 'name' | cut -d\" -f4 | head -1 )} ; \ + VERSION=${VERSION#v} ; \ + echo "KEEPALIVED_VERSION=${VERSION}" ; \ + git clone --single-branch --branch "v${VERSION}" https://github.com/acassen/keepalived.git keepalived-${VERSION} ; \ + #wget -q https://keepalived.org/software/keepalived-${VERSION}.tar.gz -O keepalived-${VERSION}.tar.gz && tar -zxf keepalived-${VERSION}.tar.gz && rm keepalived-${VERSION}.tar.gz ; \ + mv keepalived-${VERSION}/ keepalived/ ; \ + cd keepalived/ ; \ + ./autogen.sh ; \ + ./configure ; \ + make && make install ; \ + strip /usr/local/sbin/keepalived ; \ + cd .. ; \ + rm -r keepalived/ ; \ + apk del --no-network --purge .build-deps + +ENTRYPOINT ["/usr/local/sbin/keepalived","--dont-fork","--log-console", "-f","/etc/keepalived/keepalived.conf"] \ No newline at end of file diff --git a/keepalived.scratch.Dockerfile b/keepalived.scratch.Dockerfile new file mode 100644 index 0000000..9326ee5 --- /dev/null +++ b/keepalived.scratch.Dockerfile @@ -0,0 +1,64 @@ +# docker build --no-cache --progress=plain --build-arg VERSION=v2.3.1 -t tobi312/tools:keepalived -f keepalived.scratch.Dockerfile . +# https://github.com/acassen/keepalived/issues/2107#issuecomment-1049725208 +FROM alpine:latest AS build + +ARG VERSION + +RUN \ + apk add --no-cache --virtual .build-deps \ + autoconf \ + automake \ + binutils \ + gcc \ + libnl3-dev \ + #libnftnl-dev \ + #libmnl-dev \ + linux-headers \ + make \ + musl-dev \ + openssl-dev \ + \ + git \ + \ + openssl-libs-static \ + zlib-static \ + libmnl-static \ + libnl3-static \ + ; \ + VERSION=${VERSION:-$(wget -qO- https://api.github.com/repos/acassen/keepalived/tags | grep 'name' | cut -d\" -f4 | head -1 )} ; \ + VERSION=${VERSION#v} ; \ + echo "KEEPALIVED_VERSION=${VERSION}" ; \ + git clone --single-branch --branch "v${VERSION}" https://github.com/acassen/keepalived.git keepalived-${VERSION} ; \ + #wget -q https://keepalived.org/software/keepalived-${VERSION}.tar.gz -O keepalived-${VERSION}.tar.gz && tar -zxf keepalived-${VERSION}.tar.gz && rm keepalived-${VERSION}.tar.gz ; \ + mv keepalived-${VERSION}/ keepalived/ ; \ + cd keepalived/ ; \ + ./autogen.sh ; \ + CFLAGS='-static -s' LDFLAGS=-static \ + ./configure ; \ + make && make DESTDIR=/install_root install ; \ + find /install_root ; \ + rm -rf /install_root/usr/share + + +FROM scratch AS bin + +ARG VERSION + +ARG VCS_REF +ARG BUILD_DATE + +LABEL org.opencontainers.image.title="Keepalived" \ + org.opencontainers.image.authors="Alexandre Cassen , Tobias Hargesheimer " \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.revision="${VCS_REF}" \ + org.opencontainers.image.description="Keepalived is a routing software written in C" \ + org.opencontainers.image.documentation="https://keepalived.org/manpage.html , https://github.com/acassen/keepalived" \ + org.opencontainers.image.base.name="scratch" \ + org.opencontainers.image.licenses="GPL-2.0" \ + org.opencontainers.image.url="https://hub.docker.com/r/tobi312/tools" \ + org.opencontainers.image.source="https://github.com/Tob1as/docker-tools" + +COPY --from=build /install_root / + +ENTRYPOINT ["/usr/local/sbin/keepalived","--dont-fork","--log-console", "-f","/etc/keepalived/keepalived.conf", "--pid=/keepalived.pid", "--vrrp_pid=/vrrp.pid"] \ No newline at end of file