alpine docker image #609
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: alpine docker image | |
on: | |
schedule: | |
- cron: '41 3 * * *' | |
push: | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
# 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 | |
jobs: | |
# is required nightly build? | |
# More info at https://stackoverflow.com/questions/63014786/how-to-schedule-a-github-actions-nightly-build-but-run-it-only-when-there-where | |
check: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: octokit/request-action@v2.x | |
id: check_last_run | |
with: | |
route: GET /repos/{owner}/{repo}/actions/workflows/alpine.yml/runs?per_page=1&status=success | |
owner: ${{ github.repository_owner }} | |
repo: kamailio | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Show last execution info | |
run: | | |
echo "Last daily build: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].head_sha }}" | |
outputs: | |
last_sha: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].head_sha }} | |
x86_64: | |
needs: [check] | |
if: needs.check.outputs.last_sha != github.sha | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: print latest_commit | |
run: echo ${{ github.sha }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Compile Kamailio source | |
run: | | |
git submodule init | |
git submodule update | |
cd pkg/docker/alpine | |
./hooks/pre_build || true | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=pep440,pattern={{version}} | |
type=pep440,pattern={{major}}.{{minor}} | |
type=pep440,pattern={{major}} | |
type=ref,event=branch | |
flavor: | | |
suffix= | |
latest=auto | |
- name: Docker meta "-alpine" | |
id: meta-alpine | |
uses: docker/metadata-action@v5 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=pep440,pattern={{version}} | |
type=pep440,pattern={{major}}.{{minor}} | |
type=pep440,pattern={{major}} | |
type=ref,event=branch | |
flavor: | | |
suffix=-alpine | |
latest=false | |
- name: Docker meta "-debug" | |
id: meta-debug | |
uses: docker/metadata-action@v5 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=pep440,pattern={{version}} | |
type=pep440,pattern={{major}}.{{minor}} | |
type=pep440,pattern={{major}} | |
type=ref,event=branch | |
flavor: | | |
suffix=-debug | |
latest=false | |
- name: temporal workarround for "-alpine" and "-debug" builds | |
run: | | |
sudo chown -R ${USER}:${USER} ${{ github.workspace }}/pkg/docker/alpine | |
cd pkg/docker/alpine | |
mkdir repackage | |
tar xz --directory=repackage -f kamailio_min-without_os_files.tar.gz | |
rm -f kamailio_min-without_os_files.tar.gz | |
tar cz --directory=repackage -f kamailio_min-without_os_files.tar.gz $(ls -A repackage) | |
- name: Prepare local repo for "-debug" build | |
run: | | |
docker network create kamailio-build | |
docker run \ | |
--detach \ | |
--network kamailio-build \ | |
--name local-repo \ | |
--hostname local-repo \ | |
--rm=true \ | |
--volume=${{ github.workspace }}/pkg/docker/alpine/apk_files:/usr/share/nginx/html:ro \ | |
nginx | |
LOCAL_REPO_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' local-repo) | |
sed -i -e "s/local-repo/${LOCAL_REPO_IP}/" pkg/docker/alpine/Dockerfile.debug | |
- name: Create custom builder for "-debug" build | |
id: local-repo | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: | | |
network=kamailio-build | |
- name: Build and push "-debug" build | |
uses: docker/build-push-action@v6 | |
with: | |
context: pkg/docker/alpine | |
file: pkg/docker/alpine/Dockerfile.debug | |
builder: ${{ steps.local-repo.outputs.name }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta-debug.outputs.tags }} | |
labels: ${{ steps.meta-debug.outputs.labels }} | |
- name: Cleanup after "-debug" build | |
run: | | |
docker buildx stop ${{ steps.local-repo.outputs.name }} | |
docker buildx rm ${{ steps.local-repo.outputs.name }} | |
docker stop local-repo | |
docker network rm kamailio-build | |
- name: Build and push "-alpine" build | |
uses: docker/build-push-action@v6 | |
with: | |
context: pkg/docker/alpine | |
file: pkg/docker/alpine/Dockerfile.alpine | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta-alpine.outputs.tags }} | |
labels: ${{ steps.meta-alpine.outputs.labels }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: pkg/docker/alpine | |
file: pkg/docker/alpine/Dockerfile | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |