From 644cd63e23d5553dc68ec031dc8b39bbc9b0e5cc Mon Sep 17 00:00:00 2001 From: paradajz <2544094+paradajz@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:30:36 +0100 Subject: [PATCH] ci/build: rework the usage of docker container --- .devcontainer/Dockerfile.ghcr | 1 + .devcontainer/devcontainer.json | 28 +++++-- .github/workflows/ci.yml | 133 +++++++++++++++++++++----------- .github/workflows/release.yml | 53 +++++++------ docker-compose-build.yml | 16 ---- docker-compose.yml | 14 ---- scripts/dev.sh | 41 ---------- 7 files changed, 141 insertions(+), 145 deletions(-) create mode 100644 .devcontainer/Dockerfile.ghcr delete mode 100644 docker-compose-build.yml delete mode 100644 docker-compose.yml delete mode 100755 scripts/dev.sh diff --git a/.devcontainer/Dockerfile.ghcr b/.devcontainer/Dockerfile.ghcr new file mode 100644 index 000000000..908228539 --- /dev/null +++ b/.devcontainer/Dockerfile.ghcr @@ -0,0 +1 @@ +FROM ghcr.io/shanteacontrols/opendeck:latest \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 71c86c253..99656ddcb 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,10 +1,28 @@ { - "name": "Existing Docker Compose (Extend)", - "dockerComposeFile": [ - "../docker-compose.yml", + "name": "${localWorkspaceFolderBasename}", + "build": { + "dockerfile": "Dockerfile.ghcr", + "context": "${localWorkspaceFolder}" + }, + "workspaceMount": "src=${localWorkspaceFolder},dst=/home/ubuntu/project,type=bind", + "workspaceFolder": "/home/ubuntu/project", + "mounts": [ + { + "source": "${localEnv:HOME}/.gitconfig", + "target": "/etc/gitconfig", + "type": "bind" + }, + { + "source": "${localEnv:HOME}/.ssh", + "target": "/home/ubuntu/.ssh", + "type": "bind" + } + ], + "runArgs": [ + "--network=host", + "--hostname=${localWorkspaceFolderBasename}" ], - "service": "opendeck", - "workspaceFolder": "/home/ubuntu/workspace/OpenDeck", + "containerUser": "ubuntu", "customizations": { "vscode": { "extensions": [ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66b265d63..ff8ee7e81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,74 +2,113 @@ name: CI on: [push] -defaults: - run: - shell: bash -leo pipefail {0} - -env: - CCACHE_DIR: /__w/OpenDeck/OpenDeck/ccache - jobs: - build_and_test_ubuntu: - name: Build/Test [Ubuntu] - runs-on: ubuntu-22.04 - container: - image: ghcr.io/shanteacontrols/opendeck:latest - options: --user root + build: + name: Build/Test + runs-on: ubuntu-latest steps: - - name: Mark repository as safe - run: git config --global --add safe.directory /__w/OpenDeck/OpenDeck - - name: Pull the repository and submodules + - name: Pull the repository uses: actions/checkout@v4 with: fetch-depth: 0 - submodules: recursive - name: Restore ccache uses: actions/cache/restore@v4 with: - path: | - ccache - key: ccache-key - - name: Build and test targets + path: ccache + key: ccache- + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Setup missing directories and files on the runner run: | - git fetch --tags - ./scripts/build_targets.sh --type=build - ./scripts/build_targets.sh --type=test + mkdir -p ~/.ssh + touch ~/.gitconfig + - name: Prepare container + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck # Local name only + imageTag: latest # Local tag only + push: never + - name: Build and test targets + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck + imageTag: latest + push: never + runCmd: | + git fetch --tags + ./scripts/build_targets.sh --type=build + ./scripts/build_targets.sh --type=test - name: Save ccache uses: actions/cache/save@v4 + if: always() with: - path: | - ccache - key: ccache-key + path: ccache + key: "ccache-${{ github.run_id }}" format: name: Code formatting - runs-on: ubuntu-22.04 - container: - image: ghcr.io/shanteacontrols/opendeck:latest - options: --user root + runs-on: ubuntu-latest steps: - - name: Mark repository as safe - run: git config --global --add safe.directory /__w/OpenDeck/OpenDeck - - uses: actions/checkout@v4 + - name: Pull the repository + uses: actions/checkout@v4 with: fetch-depth: 0 - submodules: recursive - - name: Check formatting + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Setup missing directories and files on the runner run: | - make format + mkdir -p ~/.ssh + touch ~/.gitconfig + - name: Prepare container + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck # Local name only + imageTag: latest # Local tag only + push: never + - name: Check formatting + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck + imageTag: latest + push: never + runCmd: | + make format lint: name: Code linting - runs-on: ubuntu-22.04 - container: - image: ghcr.io/shanteacontrols/opendeck:latest - options: --user root + runs-on: ubuntu-latest steps: - - name: Mark repository as safe - run: git config --global --add safe.directory /__w/OpenDeck/OpenDeck - - uses: actions/checkout@v4 + - name: Pull the repository + uses: actions/checkout@v4 with: fetch-depth: 0 - submodules: recursive - - name: Lint + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Setup missing directories and files on the runner run: | - ./scripts/build_targets.sh --type=lint \ No newline at end of file + mkdir -p ~/.ssh + touch ~/.gitconfig + - name: Prepare container + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck # Local name only + imageTag: latest # Local tag only + push: never + - name: Check formatting + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck + imageTag: latest + push: never + runCmd: | + ./scripts/build_targets.sh --type=lint \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 674df0310..baa3f8386 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,33 +4,42 @@ on: release: types: [created] -defaults: - run: - shell: bash -leo pipefail {0} - jobs: build: name: Attach firmware to release - runs-on: ubuntu-22.04 - container: - image: ghcr.io/shanteacontrols/opendeck:latest - options: --user root + runs-on: ubuntu-latest steps: - - name: Mark repository as safe - run: git config --global --add safe.directory /__w/OpenDeck/OpenDeck - - name: Pull the repository and submodules + - name: Pull the repository uses: actions/checkout@v4 with: fetch-depth: 0 - submodules: recursive - - name: Build - run: | - git fetch --tags - ./scripts/build_targets.sh --type=build - ./scripts/copy_release_binaries.sh --build-dir=build --copy-dir=release - - name: Upload - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Setup missing directories and files on the runner run: | - tag_name="${GITHUB_REF##*/}" - hub release edit $(find ./release -type f -printf "-a %p ") -m "" "$tag_name" \ No newline at end of file + mkdir -p ~/.ssh + touch ~/.gitconfig + - name: Prepare container + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck # Local name only + imageTag: latest # Local tag only + push: never + env: | + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + - name: Build and upload + uses: devcontainers/ci@v0.3 + with: + imageName: opendeck + imageTag: latest + push: never + runCmd: | + git fetch --tags + ./scripts/build_targets.sh --type=build + ./scripts/copy_release_binaries.sh --build-dir=build --copy-dir=release + tag_name="${GITHUB_REF##*/}" + hub release edit $(find ./release -type f -printf "-a %p ") -m "" "$tag_name" \ No newline at end of file diff --git a/docker-compose-build.yml b/docker-compose-build.yml deleted file mode 100644 index 0665a138f..000000000 --- a/docker-compose-build.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: '3.7' - -services: - opendeck: - container_name: opendeck - hostname: opendeck - build: - context: . - dockerfile: .devcontainer/Dockerfile - volumes: - - $PWD:/home/ubuntu/workspace/OpenDeck - - $HOME/.ssh:/home/ubuntu/.ssh - - /dev:/dev - working_dir: /home/ubuntu/workspace/OpenDeck - command: tail -f /dev/null - privileged: true \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 666dd4a8c..000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3.7' - -services: - opendeck: - container_name: opendeck - hostname: opendeck - image: ghcr.io/shanteacontrols/opendeck - volumes: - - $PWD:/home/ubuntu/workspace/OpenDeck - - $HOME/.ssh:/home/ubuntu/.ssh - - /dev:/dev - working_dir: /home/ubuntu/workspace/OpenDeck - command: tail -f /dev/null - privileged: true \ No newline at end of file diff --git a/scripts/dev.sh b/scripts/dev.sh deleted file mode 100755 index 387ae633b..000000000 --- a/scripts/dev.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -set -e - -compose_file=docker-compose.yml - -for arg in "$@"; do - case "$arg" in - --build) - compose_file=docker-compose-build.yml - build=1 - ;; - esac -done - -# Avoid using dasel or other YAML parsers here not to introduce -# dependencies for starting a container. -container=$(cat $compose_file | grep container_name | xargs | cut -d: -f2 | xargs) - -if [[ $(docker ps | grep "${container}") != "" ]] -then - echo "Found the following containers already online:" - docker ps -f name="${container}" - - printf "\n%s" "Specify the container ID to attach to: " - read -r container - echo "Attaching to $container..." -else - echo "Creating new container" - - if [[ "$build" -eq 1 ]] - then - docker-compose -f $compose_file build - else - docker-compose -f $compose_file pull - fi - - docker-compose -f $compose_file up -d -fi - -docker exec -it "$container" bash