From 1b05124d4cf132abcdf1be279b771a9e0c069f42 Mon Sep 17 00:00:00 2001 From: Leonardo Graboski Veiga Date: Sat, 31 Aug 2024 08:30:03 -0300 Subject: [PATCH] ci: add GH Actions release workflow Add a workflow that is only triggered when a GH Release is created. Signed-off-by: Leonardo Graboski Veiga --- .github/actions/docker-build-push/action.yml | 48 ++++++++++++++++++++ .github/workflows/build-Browser.yml | 44 +++++++++++------- .github/workflows/build-DataAcquisition.yml | 44 +++++++++++------- .github/workflows/build-Grafana.yml | 44 +++++++++++------- .github/workflows/build-InfluxDB.yml | 44 +++++++++++------- .github/workflows/build-Weston.yml | 44 +++++++++++------- README.md | 2 + 7 files changed, 190 insertions(+), 80 deletions(-) create mode 100644 .github/actions/docker-build-push/action.yml diff --git a/.github/actions/docker-build-push/action.yml b/.github/actions/docker-build-push/action.yml new file mode 100644 index 0000000..7c6bc35 --- /dev/null +++ b/.github/actions/docker-build-push/action.yml @@ -0,0 +1,48 @@ +name: Docker Build and Push +description: Reusable Docker build and push logic + +inputs: + username: + description: 'Docker Hub registry username' + required: true + password: + description: 'Docker Hub password' + required: true + context: + description: 'The Docker build context' + required: true + imgarch: + description: 'Architecture of the container image' + required: true + tagname: + description: 'Docker tag name before the :' + required: true + tagversion: + description: 'Docker tag version after the :' + required: true + +runs: + using: "composite" + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ inputs.username }} + password: ${{ inputs.password }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + push: true + context: ${{ inputs.context }} + platforms: linux/${{ inputs.imgarch }} + build-args: | + IMAGE_ARCH=${{ inputs.imgarch }} + tags: | + ${{ inputs.username }}/${{ inputs.tagname }}:${{ inputs.tagversion }} diff --git a/.github/workflows/build-Browser.yml b/.github/workflows/build-Browser.yml index cc5c5d6..1f6d386 100644 --- a/.github/workflows/build-Browser.yml +++ b/.github/workflows/build-Browser.yml @@ -3,11 +3,14 @@ name: Browser env: wdir: browser arch: arm + imgname: torizon-os-build-status-browser on: push: paths: - 'browser/**' + release: + types: [created] jobs: build: @@ -20,29 +23,38 @@ jobs: - name: Git checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 + - name: Build and push release candidate + uses: ./.github/actions/docker-build-push with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + context: ${{ env.wdir }} + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: rc + + release: + needs: [build] + if: github.event_name == 'release' + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ env.wdir }} + + steps: + - name: Git checkout + uses: actions/checkout@v4 - name: Get container tag run: | echo "CONTAINER_TAG=$(jq -r '.docker_tag' .vscode/settings.json)" >> $GITHUB_ENV - - name: Build and push release candidate - uses: docker/build-push-action@v5 + - name: Build and push tagged release + uses: ./.github/actions/docker-build-push with: - push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} context: ${{ env.wdir }} - platforms: linux/${{ env.arch }} - build-args: | - IMAGE_ARCH=${{ env.arch }} - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/torizon-os-build-status-browser:rc + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: ${{ env.CONTAINER_TAG }} diff --git a/.github/workflows/build-DataAcquisition.yml b/.github/workflows/build-DataAcquisition.yml index f1b9d1a..084bc0f 100644 --- a/.github/workflows/build-DataAcquisition.yml +++ b/.github/workflows/build-DataAcquisition.yml @@ -3,11 +3,14 @@ name: Data Acquisition App env: wdir: dataAcquisition arch: arm64 + imgname: torizon-os-build-status-data-acquisition on: push: paths: - 'dataAcquisition/**' + release: + types: [created] jobs: build: @@ -20,29 +23,38 @@ jobs: - name: Git checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 + - name: Build and push release candidate + uses: ./.github/actions/docker-build-push with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + context: ${{ env.wdir }} + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: rc + + release: + needs: [build] + if: github.event_name == 'release' + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ env.wdir }} + + steps: + - name: Git checkout + uses: actions/checkout@v4 - name: Get container tag run: | echo "CONTAINER_TAG=$(jq -r '.docker_tag' .vscode/settings.json)" >> $GITHUB_ENV - - name: Build and push release candidate - uses: docker/build-push-action@v5 + - name: Build and push tagged release + uses: ./.github/actions/docker-build-push with: - push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} context: ${{ env.wdir }} - platforms: linux/${{ env.arch }} - build-args: | - IMAGE_ARCH=${{ env.arch }} - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/torizon-os-build-status-data-acquisition:rc + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: ${{ env.CONTAINER_TAG }} diff --git a/.github/workflows/build-Grafana.yml b/.github/workflows/build-Grafana.yml index 8210a2c..7e1d41f 100644 --- a/.github/workflows/build-Grafana.yml +++ b/.github/workflows/build-Grafana.yml @@ -3,11 +3,14 @@ name: Grafana env: wdir: grafana arch: arm64 + imgname: torizon-os-build-status-grafana on: push: paths: - 'grafana/**' + release: + types: [created] jobs: build: @@ -20,29 +23,38 @@ jobs: - name: Git checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 + - name: Build and push release candidate + uses: ./.github/actions/docker-build-push with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + context: ${{ env.wdir }} + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: rc + + release: + needs: [build] + if: github.event_name == 'release' + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ env.wdir }} + + steps: + - name: Git checkout + uses: actions/checkout@v4 - name: Get container tag run: | echo "CONTAINER_TAG=$(jq -r '.docker_tag' .vscode/settings.json)" >> $GITHUB_ENV - - name: Build and push release candidate - uses: docker/build-push-action@v5 + - name: Build and push tagged release + uses: ./.github/actions/docker-build-push with: - push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} context: ${{ env.wdir }} - platforms: linux/${{ env.arch }} - build-args: | - IMAGE_ARCH=${{ env.arch }} - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/torizon-os-build-status-grafana:rc + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: ${{ env.CONTAINER_TAG }} diff --git a/.github/workflows/build-InfluxDB.yml b/.github/workflows/build-InfluxDB.yml index 6d3ef94..407706c 100644 --- a/.github/workflows/build-InfluxDB.yml +++ b/.github/workflows/build-InfluxDB.yml @@ -3,11 +3,14 @@ name: InfluxDB env: wdir: influxdb arch: arm64 + imgname: torizon-os-build-status-influxdb on: push: paths: - 'influxdb/**' + release: + types: [created] jobs: build: @@ -20,29 +23,38 @@ jobs: - name: Git checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 + - name: Build and push release candidate + uses: ./.github/actions/docker-build-push with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + context: ${{ env.wdir }} + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: rc + + release: + needs: [build] + if: github.event_name == 'release' + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ env.wdir }} + + steps: + - name: Git checkout + uses: actions/checkout@v4 - name: Get container tag run: | echo "CONTAINER_TAG=$(jq -r '.docker_tag' .vscode/settings.json)" >> $GITHUB_ENV - - name: Build and push release candidate - uses: docker/build-push-action@v5 + - name: Build and push tagged release + uses: ./.github/actions/docker-build-push with: - push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} context: ${{ env.wdir }} - platforms: linux/${{ env.arch }} - build-args: | - IMAGE_ARCH=${{ env.arch }} - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/torizon-os-build-status-influxdb:rc + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: ${{ env.CONTAINER_TAG }} diff --git a/.github/workflows/build-Weston.yml b/.github/workflows/build-Weston.yml index 52cff93..daf9a9c 100644 --- a/.github/workflows/build-Weston.yml +++ b/.github/workflows/build-Weston.yml @@ -3,11 +3,14 @@ name: Weston env: wdir: weston arch: arm + imgname: torizon-os-build-status-weston on: push: paths: - 'weston/**' + release: + types: [created] jobs: build: @@ -20,29 +23,38 @@ jobs: - name: Git checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 + - name: Build and push release candidate + uses: ./.github/actions/docker-build-push with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + context: ${{ env.wdir }} + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: rc + + release: + needs: [build] + if: github.event_name == 'release' + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ env.wdir }} + + steps: + - name: Git checkout + uses: actions/checkout@v4 - name: Get container tag run: | echo "CONTAINER_TAG=$(jq -r '.docker_tag' .vscode/settings.json)" >> $GITHUB_ENV - - name: Build and push release candidate - uses: docker/build-push-action@v5 + - name: Build and push tagged release + uses: ./.github/actions/docker-build-push with: - push: true + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} context: ${{ env.wdir }} - platforms: linux/${{ env.arch }} - build-args: | - IMAGE_ARCH=${{ env.arch }} - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/torizon-os-build-status-weston:rc + imgarch: ${{ env.arch }} + tagname: ${{ env.imgname }} + tagversion: ${{ env.CONTAINER_TAG }} diff --git a/README.md b/README.md index 0b63b45..ac6f3ea 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,5 @@ recommended that you use VS Code and install the Torizon IDE extension. 💡 for debugging the data gathering (Jenkins --> InfluxDB --> Grafana), use the sub-project `dataAcquisition`. Read the [dataAcquisition README](./dataAcquisition/.doc/README.md) for details. + +For debugging the GH Actions pipelines, it is recommended to use [act](https://nektosact.com/).