From aa60ed6f492a45b94e31bf61b7b8376c8f521ce7 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 13 Oct 2023 11:21:11 +0200 Subject: [PATCH] github: action to refresh builder-alpine.${ALPINE_BRANCH} image --- .github/dependabot.yml | 9 ++++++ .github/workflows/builder.yml | 53 +++++++++++++++++++++++++++++++++++ alpine/hooks/pre_build | 22 ++++++++++----- 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/builder.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..775cd54 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,9 @@ +--- +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "github: [skip ci]" diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml new file mode 100644 index 0000000..06c9fa6 --- /dev/null +++ b/.github/workflows/builder.yml @@ -0,0 +1,53 @@ +--- +name: alpine docker builder image +on: + push: + branches: + - master + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + IMAGE_NAME: kamailio-ci + SOURCE_BRANCH: ${{ github.ref_name }} + DOCKER_REPO: ghcr.io/kamailio/kamailio-ci + REFRESH_ONLY: true + +jobs: + x86_64: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: print latest_commit + run: echo ${{ github.sha }} + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v39 + with: + since_last_remote_commit: true + + - name: Dockerfile.builder + id: changed-files-builder + uses: tj-actions/changed-files@v39 + with: + files: alpine/Dockerfile.builder + + - name: Login to GitHub Container Registry + if: steps.changed-files-builder.outputs.any_changed == 'true' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: generate builder + if: steps.changed-files-builder.outputs.any_changed == 'true' + run: | + ./alpine/hooks/pre_build diff --git a/alpine/hooks/pre_build b/alpine/hooks/pre_build index 6c814af..abf4292 100755 --- a/alpine/hooks/pre_build +++ b/alpine/hooks/pre_build @@ -5,19 +5,22 @@ set -x # Setting environment vars ALPINE_BRANCH="${ALPINE_BRANCH:-latest}" DOCKER_REPO="${DOCKER_REPO:-kamailio/kamailio-ci}" +REFRESH_ONLY="${REFRESH_ONLY:-false}" if [ "$SOURCE_BRANCH" = "master" ];then ALPINE_BRANCH="edge" fi refresh_builder() { - docker pull alpine:${ALPINE_BRANCH} || true - docker pull ${DOCKER_REPO}:builder-alpine.${ALPINE_BRANCH} || true - local SHA_ALPINE=$(docker image inspect -f '{{index .RootFS.Layers 0}}' alpine:${ALPINE_BRANCH}) - local SHA_BUILDER=$(docker image inspect -f '{{index .RootFS.Layers 0}}' ${DOCKER_REPO}:builder-alpine.${ALPINE_BRANCH}) - if [ "${SHA_ALPINE}" = "${SHA_BUILDER}" ]; then - echo "Builder already use fresh alpine base image. Continue" - return 0 + docker pull alpine:${ALPINE_BRANCH} + if ! ${REFRESH_ONLY} ; then + docker pull ${DOCKER_REPO}:builder-alpine.${ALPINE_BRANCH} + local SHA_ALPINE=$(docker image inspect -f '{{index .RootFS.Layers 0}}' alpine:${ALPINE_BRANCH}) + local SHA_BUILDER=$(docker image inspect -f '{{index .RootFS.Layers 0}}' ${DOCKER_REPO}:builder-alpine.${ALPINE_BRANCH}) + if [ "${SHA_ALPINE}" = "${SHA_BUILDER}" ]; then + echo "Builder already use fresh alpine base image. Continue" + return 0 + fi fi sed -i -e "s/alpine:latest/alpine:${ALPINE_BRANCH}/" Dockerfile.builder docker build -t ${DOCKER_REPO}:builder-alpine.${ALPINE_BRANCH} --file Dockerfile.builder . @@ -29,6 +32,11 @@ refresh_builder() { echo "=> Refreshing builder image" refresh_builder +if ${REFRESH_ONLY} ; then + echo "=> REFRESH_ONLY detected, done" + return 0 +fi + echo "=> Build Kamailio source code" if [ "${ALPINE_BRANCH}" = "edge" ]; then