From d9d6f201ae880faf292117c9f8ec5a7f89989f17 Mon Sep 17 00:00:00 2001 From: Dejan Jovasevic Date: Mon, 4 Sep 2023 16:31:06 +0200 Subject: [PATCH] Saved docker as release artifact - Create an action for uploading to release - The release and tag will be created before this is run - Use the shell script to create the docker image from sources -> Save the image and gzip it -> Upload it to created release --- .github/actions/upload-assets/upload.sh | 51 +++++++++++++++++++++++++ .github/workflows/build.yml | 38 ++++++++++++++++-- setup/docker.sh | 15 ++++---- 3 files changed, 94 insertions(+), 10 deletions(-) create mode 100755 .github/actions/upload-assets/upload.sh diff --git a/.github/actions/upload-assets/upload.sh b/.github/actions/upload-assets/upload.sh new file mode 100755 index 0000000..0e31447 --- /dev/null +++ b/.github/actions/upload-assets/upload.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +function show_help() { + echo " Usage:" + echo " bash ${PATH_TO_DIR}/upload.sh [--repo_name REPONAME] [--file_name FILENAME]" + echo + echo " --reponame Name of repo to upload too." + echo " --filename Name of file to upload." + echo " -h|--help Print this help." +} + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --reponame) + REPONAME="$2" + shift + shift + ;; + --filename) + FILENAME="$2" + shift + shift + ;; + -h|--help) + show_help + exit 0 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +ID_OF_RELEASE=$(curl --fail -s -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/DolbyIO/${REPONAME}/releases/tags/${GITHUB_REF_NAME} | jq ".id") + +echo "uploading file ${FILENAME} for tag: ${GITHUB_REF_NAME} for ID: ${ID_OF_RELEASE}" + +curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: token ${GITHUB_TOKEN}"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/gzip" \ + https://uploads.github.com/repos/DolbyIO/${REPONAME}/releases/${ID_OF_RELEASE}/assets?name=${1}\ + --data-binary "@${FILENAME}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ddd3ac2..dabf797 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: Build RTME env: - DOCKER_HUB_REPO: "voxeet/real-time-media-extensions" + DOCKER_HUB_REPO: "dolbyio/real-time-media-extensions" on: pull_request: @@ -48,9 +48,10 @@ jobs: name: docker-resource path: docker-resource.zip retention-days: 1 - + + # Disable this job for now until repo is set build-deploy-docker: - if: github.ref_type == 'tag' + if: false runs-on: ubuntu-20.04 needs: build-resources steps: @@ -87,3 +88,34 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + build-save-docker: + if: github.ref_type == 'tag' + runs-on: ubuntu-20.04 + needs: build-resources + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Download docker resources + uses: actions/download-artifact@v3 + with: + name: docker-resource + + - name: Build and release docker + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + unzip docker-resource.zip && rm docker-resource.zip + sudo bash setup/linux.sh --build_docker ${{ env.DOCKER_HUB_REPO }} ${GITHUB_REF_NAME} --skip_building + ls -l + sudo chmod 777 dolbyio_rtme-${GITHUB_REF_NAME}.tar.gz + gh release upload ${GITHUB_REF_NAME} dolbyio_rtme-${GITHUB_REF_NAME}.tar.gz + #sudo bash .github/actions/upload-assets/upload.sh --filename dolbyio_rtme-${GITHUB_REF_NAME}.tar.gz --reponame real-time-media-extensions + + - name: Upload docker package + uses: actions/upload-artifact@v3 + with: + name: docker-rtme-image + path: dolbyio_rtme-${GITHUB_REF_NAME}.tar.gz + retention-days: 7 diff --git a/setup/docker.sh b/setup/docker.sh index 1184465..bae0739 100644 --- a/setup/docker.sh +++ b/setup/docker.sh @@ -29,11 +29,12 @@ prepare_docker_image() { } build_docker_image() { - docker_repo=${1} - docker_tag=${2} - pushd ${WORK_DIR} - docker build -t ${docker_repo}:${docker_tag} -f Dockerfile --no-cache . - docker save --output dolbyio_rtme-${docker_tag}.tar ${docker_repo}:${docker_tag} - gzip -9 dolbyio_rtme-${docker_tag}.tar - popd + docker_repo=${1} + docker_tag=${2} + pushd ${WORK_DIR} + docker build -t ${docker_repo}:${docker_tag} -f Dockerfile --no-cache . + docker save --output dolbyio_rtme-${docker_tag}.tar ${docker_repo}:${docker_tag} + gzip -9 dolbyio_rtme-${docker_tag}.tar + ls -l + popd }