diff --git a/.github/workflows/aas-amd64-main.yml b/.github/workflows/aas-amd64-main.yml new file mode 100644 index 00000000..48f497b7 --- /dev/null +++ b/.github/workflows/aas-amd64-main.yml @@ -0,0 +1,137 @@ +name: aas ci/cd main + +on: + schedule: + - cron: '0 3 * * 6' + workflow_dispatch: {} + pull_request: + branches: [ "main" ] + +permissions: + contents: read + packages: write + +jobs: + build-aircraft: + uses: ./.github/workflows/aircraft-amd64-build.yml + + build-ground: + uses: ./.github/workflows/ground-amd64-build.yml + + build-simulation: + uses: ./.github/workflows/simulation-amd64-build.yml + + integration-test: + runs-on: ubuntu-22.04 + needs: [build-aircraft, build-ground, build-simulation] + timeout-minutes: 150 + permissions: + contents: read + packages: read + defaults: + run: + shell: bash -el {0} + + steps: + - name: Free disk space + run: | + sudo rm -rf /usr/share/dotnet & + sudo rm -rf /usr/local/lib/android & + sudo rm -rf /opt/ghc & + sudo rm -rf /opt/hostedtoolcache/CodeQL & + sudo rm -rf /usr/local/share/boost & + sudo rm -rf /usr/share/swift & + sudo rm -rf "$AGENT_TOOLSDIRECTORY" & + wait + sudo docker image prune --all --force + sudo apt-get clean + sudo rm -rf /var/lib/apt/lists/* + + - name: Add swap space + run: | + sudo swapoff -a || true + sudo rm -f /swapfile + sudo fallocate -l 10G /swapfile + sudo chmod 600 /swapfile + sudo mkswap /swapfile + sudo swapon /swapfile + + - name: Check swap + run: | + free -h + sudo swapon --show + + - name: Check disk space + run: df -h + + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine Docker tag + env: + EVENT_NAME: ${{ github.event_name }} + EVENT_NUMBER: ${{ github.event.number }} + REF_NAME: ${{ github.ref_name }} + REF: ${{ github.ref }} + run: | + if [ "$EVENT_NAME" == "pull_request" ]; then + echo "DOCKER_TAG=pr-${EVENT_NUMBER}" >> $GITHUB_ENV + elif [ "$REF" == "refs/heads/main" ]; then + echo "DOCKER_TAG=latest" >> $GITHUB_ENV + else + BRANCH_TAG=$(echo "$REF_NAME" | tr '/' '-') + echo "DOCKER_TAG=${BRANCH_TAG}" >> $GITHUB_ENV + fi + + - name: Pull and re-tag images + run: | + echo "Pulling images with tag: ${{ env.DOCKER_TAG }}" + docker pull ghcr.io/jacopopan/aircraft-image:${{ env.DOCKER_TAG }} + docker pull ghcr.io/jacopopan/ground-image:${{ env.DOCKER_TAG }} + docker pull ghcr.io/jacopopan/simulation-image:${{ env.DOCKER_TAG }} + echo "Locally retagging the images as latest for aas_env.py" + docker tag ghcr.io/jacopopan/aircraft-image:${{ env.DOCKER_TAG }} aircraft-image:latest + docker tag ghcr.io/jacopopan/ground-image:${{ env.DOCKER_TAG }} ground-image:latest + docker tag ghcr.io/jacopopan/simulation-image:${{ env.DOCKER_TAG }} simulation-image:latest + docker images | grep latest + + - name: Set up Conda with Python 3.13 + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: aas + python-version: 3.13 + auto-activate: true + use-only-tar-bz2: true + + - name: Remove GPU requests + run: | + sed -i 's/devices=device_binds,/devices=[],/' ./aas-gym/src/aas_gym/aas_env.py + sed -i 's/device_requests=gpu_requests,/device_requests=[],/' ./aas-gym/src/aas_gym/aas_env.py + + - name: Install aas-gym package + run: | + cd ./aas-gym/ + pip install -e . + + - name: Run aas-gym test 1 + run: | + python3 ./scripts/gym_run.py --mode speedup --num_quads 1 --no-camera --no-lidar --autopilot px4 + + - name: Safety cleanup between tests + if: always() + run: | + docker kill $(docker ps -q) || true + docker rm $(docker ps -a -q) || true + docker network prune -f + sleep 10 + + - name: Run aas-gym test 2 + run: | + python3 ./scripts/gym_run.py --mode speedup --num_quads 1 --no-camera --no-lidar --autopilot ardupilot diff --git a/.github/workflows/aas-gym-pip-install.yml b/.github/workflows/aas-gym-pip-install.yml index 762f604c..20ce89af 100644 --- a/.github/workflows/aas-gym-pip-install.yml +++ b/.github/workflows/aas-gym-pip-install.yml @@ -43,7 +43,7 @@ jobs: with: activate-environment: aas python-version: 3.13 - auto-activate-base: false + auto-activate: true use-only-tar-bz2: true - name: Install aas-gym package diff --git a/.github/workflows/aircraft-amd64-build.yml b/.github/workflows/aircraft-amd64-build.yml index 95e3b477..e9935016 100644 --- a/.github/workflows/aircraft-amd64-build.yml +++ b/.github/workflows/aircraft-amd64-build.yml @@ -1,11 +1,7 @@ name: aircraft-image amd64 on: - schedule: - - cron: '0 3 * * 6' - workflow_dispatch: {} - pull_request: - branches: [ "main" ] + workflow_call: {} jobs: build: @@ -63,5 +59,21 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build the aircraft image (optionally, add --push) - run: docker buildx build -t ghcr.io/jacopopan/aircraft-image:latest -f ./scripts/docker/Dockerfile.aircraft . + - name: Determine Docker tag + env: + EVENT_NAME: ${{ github.event_name }} + EVENT_NUMBER: ${{ github.event.number }} + REF_NAME: ${{ github.ref_name }} + REF: ${{ github.ref }} + run: | + if [ "$EVENT_NAME" == "pull_request" ]; then + echo "DOCKER_TAG=pr-${EVENT_NUMBER}" >> $GITHUB_ENV + elif [ "$REF" == "refs/heads/main" ]; then + echo "DOCKER_TAG=latest" >> $GITHUB_ENV + else + BRANCH_TAG=$(echo "$REF_NAME" | tr '/' '-') + echo "DOCKER_TAG=${BRANCH_TAG}" >> $GITHUB_ENV + fi + + - name: Build the aircraft + run: docker buildx build --push -t ghcr.io/jacopopan/aircraft-image:${{ env.DOCKER_TAG }} -f ./scripts/docker/Dockerfile.aircraft . diff --git a/.github/workflows/cleanup-packages.yml b/.github/workflows/cleanup-packages.yml new file mode 100644 index 00000000..1d3a008d --- /dev/null +++ b/.github/workflows/cleanup-packages.yml @@ -0,0 +1,26 @@ +name: cleanup packages + +on: + schedule: + - cron: '0 3 * * 0' + workflow_dispatch: {} + +jobs: + delete-old-versions: + runs-on: ubuntu-22.04 + permissions: + packages: write + + steps: + - name: Prune images older than 10 days (except latest) + uses: snok/container-retention-policy@v3.0.0 + with: + image-names: | + aircraft-image + ground-image + simulation-image + cut-off: 10d + skip-tags: latest + keep-at-least: 1 + account-type: personal + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ground-amd64-build.yml b/.github/workflows/ground-amd64-build.yml index 950c280e..2b55c0b1 100644 --- a/.github/workflows/ground-amd64-build.yml +++ b/.github/workflows/ground-amd64-build.yml @@ -1,11 +1,7 @@ name: ground-image amd64 on: - schedule: - - cron: '0 3 * * 6' - workflow_dispatch: {} - pull_request: - branches: [ "main" ] + workflow_call: {} jobs: build: @@ -63,5 +59,21 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build the ground image (optionally, add --push) - run: docker buildx build -t ghcr.io/jacopopan/ground-image:latest -f ./scripts/docker/Dockerfile.ground . + - name: Determine Docker tag + env: + EVENT_NAME: ${{ github.event_name }} + EVENT_NUMBER: ${{ github.event.number }} + REF_NAME: ${{ github.ref_name }} + REF: ${{ github.ref }} + run: | + if [ "$EVENT_NAME" == "pull_request" ]; then + echo "DOCKER_TAG=pr-${EVENT_NUMBER}" >> $GITHUB_ENV + elif [ "$REF" == "refs/heads/main" ]; then + echo "DOCKER_TAG=latest" >> $GITHUB_ENV + else + BRANCH_TAG=$(echo "$REF_NAME" | tr '/' '-') + echo "DOCKER_TAG=${BRANCH_TAG}" >> $GITHUB_ENV + fi + + - name: Build the ground image + run: docker buildx build --push -t ghcr.io/jacopopan/ground-image:${{ env.DOCKER_TAG }} -f ./scripts/docker/Dockerfile.ground . diff --git a/.github/workflows/simulation-amd64-build.yml b/.github/workflows/simulation-amd64-build.yml index 7acfe167..41f2eeec 100644 --- a/.github/workflows/simulation-amd64-build.yml +++ b/.github/workflows/simulation-amd64-build.yml @@ -1,11 +1,7 @@ name: simulation-image amd64 on: - schedule: - - cron: '0 3 * * 6' - workflow_dispatch: {} - pull_request: - branches: [ "main" ] + workflow_call: {} jobs: build: @@ -63,5 +59,21 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build the simulation image (optionally, add --push) - run: docker buildx build -t ghcr.io/jacopopan/simulation-image:latest -f ./scripts/docker/Dockerfile.simulation . + - name: Determine Docker tag + env: + EVENT_NAME: ${{ github.event_name }} + EVENT_NUMBER: ${{ github.event.number }} + REF_NAME: ${{ github.ref_name }} + REF: ${{ github.ref }} + run: | + if [ "$EVENT_NAME" == "pull_request" ]; then + echo "DOCKER_TAG=pr-${EVENT_NUMBER}" >> $GITHUB_ENV + elif [ "$REF" == "refs/heads/main" ]; then + echo "DOCKER_TAG=latest" >> $GITHUB_ENV + else + BRANCH_TAG=$(echo "$REF_NAME" | tr '/' '-') + echo "DOCKER_TAG=${BRANCH_TAG}" >> $GITHUB_ENV + fi + + - name: Build the simulation image + run: docker buildx build --push -t ghcr.io/jacopopan/simulation-image:${{ env.DOCKER_TAG }} -f ./scripts/docker/Dockerfile.simulation . diff --git a/README.md b/README.md index 433e26e5..9033e6c5 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,8 @@ cd aerial-autonomy-stack/scripts/ ./sim_build.sh # Note: the 1st build takes ~30GB of space and ~25' with good internet (`Ctrl + c` and restart if needed) +# Alternatively, pre-build images are available on ghcr.io: +# docker pull ghcr.io/jacopopan/[aircraft|ground|simulation]-image:latest ```