trigger-dspace-workflow #379
This file contains hidden or 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: AI Racing Tech dSpace IAC sut-te-bridge Docker | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: ["art-jazzy"] | |
| pull_request: | |
| branches: ["art-jazzy"] | |
| repository_dispatch: | |
| types: ["trigger-dspace-workflow"] | |
| concurrency: | |
| group: bridge-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-push: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - SAVE_NAME: iac_dspace_bridge_dev | |
| TARGET: dspace_bridge_dev | |
| ECR_REPO: iac_dspace_bridge_dev | |
| - SAVE_NAME: iac_asm_socketcan_bridge | |
| TARGET: asm_socketcan_bridge | |
| ECR_REPO: iac_asm_socketcan_bridge | |
| - SAVE_NAME: iac_socketcan_dbw_bridge | |
| TARGET: socketcan_dbw_bridge | |
| ECR_REPO: iac_socketcan_dbw_bridge | |
| - SAVE_NAME: iac_aurelion_ros2_bridge | |
| TARGET: aurelion_ros2_bridge | |
| ECR_REPO: iac_aurelion_ros2_bridge | |
| - SAVE_NAME: iac_ros2_foxglove_bridge | |
| TARGET: ros2_foxglove_bridge | |
| ECR_REPO: foxglove | |
| outputs: | |
| tag_name: ${{ steps.save_tag.outputs.tag_name }} | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - name: Setup SSH | |
| uses: webfactory/ssh-agent@v0.9.0 | |
| with: | |
| ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: airacingtechba | |
| password: ${{ secrets.PAT }} | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| install: true | |
| ssh: true | |
| - name: Get the Ref | |
| id: get-ref | |
| uses: sisaha9/ref-to-tag-action@v2 | |
| with: | |
| ref: ${{ github.ref }} | |
| head_ref: ${{ github.head_ref }} | |
| - name: Determine dispatch inputs | |
| id: dispatch_inputs | |
| run: | | |
| set -euo pipefail | |
| if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then | |
| tag="${{ github.event.client_payload.tag_name || '' }}" | |
| base="${{ github.event.client_payload.image_name || '' }}" | |
| if [[ -z "${tag}" || -z "${base}" ]]; then | |
| echo "Repository dispatch missing tag_name or image_name in client_payload" >&2 | |
| exit 1 | |
| fi | |
| else | |
| tag="${{ steps.get-ref.outputs.tag }}" | |
| base="ghcr.io/airacingtech/art_ros_jazzy_cpu-built-dspace:stable" | |
| fi | |
| echo "tag=${tag}" >> "${GITHUB_OUTPUT}" | |
| echo "base_image=${base}" >> "${GITHUB_OUTPUT}" | |
| - name: Free Disk Space (Ubuntu) | |
| uses: jlumbroso/free-disk-space@v1.3.1 | |
| with: | |
| tool-cache: true | |
| - name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache-${{ matrix.SAVE_NAME }} | |
| key: ${{ runner.os }}-buildx-dev-${{ matrix.SAVE_NAME }}-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx-dev-${{ matrix.SAVE_NAME }} | |
| ${{ runner.os }}-buildx-dev | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| pull: true | |
| push: true | |
| tags: | | |
| ghcr.io/airacingtech/${{ matrix.SAVE_NAME }}:${{ steps.dispatch_inputs.outputs.tag }} | |
| ssh: | | |
| default=${{ env.SSH_AUTH_SOCK }} | |
| cache-from: type=local,src=/tmp/.buildx-cache-${{ matrix.SAVE_NAME }} | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new-${{ matrix.SAVE_NAME }},mode=max | |
| build-args: | | |
| BASE_IMAGE=${{ steps.dispatch_inputs.outputs.base_image }} | |
| target: ${{ matrix.TARGET }} | |
| - name: Delete old cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache-${{ matrix.SAVE_NAME }} | |
| mv /tmp/.buildx-cache-new-${{ matrix.SAVE_NAME }} /tmp/.buildx-cache-${{ matrix.SAVE_NAME }} | |
| - name: Save tag name to Github Output | |
| id: save_tag | |
| run: | | |
| echo "tag_name=${{ steps.dispatch_inputs.outputs.tag }}" >> $GITHUB_OUTPUT | |
| aws-push: | |
| runs-on: ubuntu-latest | |
| needs: [build-push] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - SAVE_NAME: iac_dspace_bridge_dev | |
| ECR_REPO: iac_dspace_bridge_dev | |
| - SAVE_NAME: iac_asm_socketcan_bridge | |
| ECR_REPO: iac_asm_socketcan_bridge | |
| - SAVE_NAME: iac_socketcan_dbw_bridge | |
| ECR_REPO: iac_socketcan_dbw_bridge | |
| - SAVE_NAME: iac_aurelion_ros2_bridge | |
| ECR_REPO: iac_aurelion_ros2_bridge | |
| - SAVE_NAME: iac_ros2_foxglove_bridge | |
| ECR_REPO: foxglove | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: airacingtechba | |
| password: ${{ secrets.PAT }} | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.DSPACE_AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.DSPACE_AWS_SECRET_ACCESS_KEY }} | |
| aws-region: eu-central-1 | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Pull, tag, and push image to Amazon ECR | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| IMAGE_TAG: ${{ needs.build-push.outputs.tag_name }} | |
| TEAM_NAME: ai-racing | |
| run: | | |
| GHCR_IMAGE="ghcr.io/airacingtech/${{ matrix.SAVE_NAME }}:${IMAGE_TAG}" | |
| ECR_IMAGE="${ECR_REGISTRY}/${TEAM_NAME}/${{ matrix.ECR_REPO }}:${IMAGE_TAG}" | |
| docker pull "${GHCR_IMAGE}" | |
| docker tag "${GHCR_IMAGE}" "${ECR_IMAGE}" | |
| docker push "${ECR_IMAGE}" |