add docker build system #12
Workflow file for this run
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 and push base docker images | |
# scheduled run every day at 00:00 GMT +03:00 | |
on: | |
workflow_dispatch: | |
pull_request: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 21 * * *" | |
concurrency: | |
group: base_images | |
cancel-in-progress: true | |
env: | |
DESKTOP_IMAGE_TAG: ghcr.io/itu-auv/auv-software-desktop-base | |
TEGRA_IMAGE_TAG: ghcr.io/itu-auv/auv-software-tegra-base | |
BASE_IMAGE_TAG: ghcr.io/itu-auv/auv-software-base | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
host: [desktop, tegra] | |
include: | |
# configuration for desktop base image | |
- base_image: ros:noetic-ros-base | |
platform: linux/amd64 | |
architecture: amd64 | |
host: desktop | |
# configuration for tegra base image | |
- base_image: dustynv/ros:noetic-ros-base-l4t-r35.2.1 | |
platform: linux/arm64 | |
architecture: arm64 | |
host: tegra | |
steps: | |
- name: Get matrix info | |
id: matrix_info | |
run: | | |
if [ "${{ matrix.host }}" == "desktop" ]; then | |
echo "image_tag=${{ env.DESKTOP_IMAGE_TAG }}" >> $GITHUB_OUTPUT | |
elif [ "${{ matrix.host }}" == "tegra" ]; then | |
echo "image_tag=${{ env.TEGRA_IMAGE_TAG }}" >> $GITHUB_OUTPUT | |
else | |
exit 1 | |
fi | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Github Containter Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push base image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./docker/Dockerfile.auv-base | |
platforms: ${{ matrix.platform }} | |
push: true | |
build-args: | | |
BASE_IMAGE=${{ matrix.base_image }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
${{ steps.matrix_info.outputs.image_tag }}:latest | |
${{ steps.matrix_info.outputs.image_tag }}:${{ github.sha }} | |
create-manifests: | |
runs-on: ubuntu-latest | |
needs: [build-and-push] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Login to Github Containter Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create SHA manifest and push | |
run: | | |
docker manifest create \ | |
${{ env.BASE_IMAGE_TAG }}:${{ github.sha }} \ | |
--amend ${{ env.DESKTOP_IMAGE_TAG }}:${{ github.sha }} \ | |
--amend ${{ env.TEGRA_IMAGE_TAG }}:${{ github.sha }} | |
docker manifest push ${{ env.BASE_IMAGE_TAG }}:${{ github.sha }} | |
- name: Create latest manifest and push | |
run: | | |
docker manifest create \ | |
${{ env.BASE_IMAGE_TAG }}:latest \ | |
--amend ${{ env.DESKTOP_IMAGE_TAG }}:latest \ | |
--amend ${{ env.TEGRA_IMAGE_TAG }}:latest | |
docker manifest push ${{ env.BASE_IMAGE_TAG }}:latest |