Build Docker image #246
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: Build Docker image | |
# Controls when the action will run. | |
on: | |
# Triggers the workflow on all push or pull request events | |
push: | |
pull_request: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * *" | |
# added using https://github.com/step-security/secure-repo | |
permissions: | |
contents: read | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
Docker: | |
name: Build&Push to DockerHub | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_REPO: sippylabs/webrtc_phone | |
BASE_IMAGE: sippylabs/rtpproxy:latest-ubuntu_latest | |
DOCKER_RW: ${{ ( github.repository == 'sippy/webrtc_phone' && github.event_name != 'pull_request' ) && 'true' || 'false' }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
- name: Checkout SIP.js repo | |
uses: actions/checkout@v4 | |
with: | |
repository: 'onsip/SIP.js' | |
path: docker/SIP.js | |
- name: Checkout SaraPhone repo | |
uses: actions/checkout@v4 | |
with: | |
repository: 'gmaruzz/saraphone' | |
path: docker/SIP.js/demo/saraphone | |
- name: Checkout Sippy B2BUA repo | |
uses: actions/checkout@v4 | |
with: | |
repository: 'sippy/b2bua' | |
path: docker/b2bua | |
ref: master | |
- name: Build SIP.js & SaraPhone | |
run: | | |
sh -x build/SIP.js.sh | |
sh -x build/saraphone.sh | |
- name: Set up QEMU | |
id: qemu | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64,arm,riscv64,mips64le,ppc64le,s390x | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
if: ${{ env.DOCKER_RW }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_REPO }} | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=tag | |
type=ref,event=pr | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=sha | |
- name: Set build environment | |
run: | | |
echo "GIT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV | |
PLATFORMS="`docker manifest inspect ${{ env.BASE_IMAGE }} | jq -r '.manifests[] | \ | |
"\(.platform.os)/\(.platform.architecture)"' | sort -u | grep -v unknown | paste -sd ','`" | |
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV | |
- name: Build Docker image | |
uses: docker/build-push-action@v6 | |
env: | |
CACHE_SPEC: "type=registry,ref=${{ env.DOCKER_REPO }}:${{ env.GIT_BRANCH }}-buildcache" | |
with: | |
context: . | |
file: ./Dockerfile | |
build-args: BASE_IMAGE=${{ env.BASE_IMAGE }} | |
push: ${{ env.DOCKER_RW }} | |
tags: | | |
${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: ${{ env.PLATFORMS }} | |
cache-from: ${{ env.CACHE_SPEC }} | |
cache-to: ${{ env.CACHE_SPEC }},mode=max | |
- name: Update DockerHub repo description | |
if: ${{ env.DOCKER_RW }} && ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
run: sh -x docker/update_description.sh README.md |