Skip to content

Commit

Permalink
github: action to refresh builder-alpine.${ALPINE_BRANCH} image
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed Oct 13, 2023
1 parent cf48a82 commit 08f1976
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "github: [skip ci]"
53 changes: 53 additions & 0 deletions .github/workflows/builder.yml
Original file line number Diff line number Diff line change
@@ -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: |
./hooks/pre_build
22 changes: 15 additions & 7 deletions alpine/hooks/pre_build
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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
Expand Down

0 comments on commit 08f1976

Please sign in to comment.