From fae47ecd662d3b8359dbe3863bf7778c3363260e Mon Sep 17 00:00:00 2001 From: Dragos Gheorghioiu Date: Fri, 31 Jul 2026 17:45:29 +0300 Subject: [PATCH] fix: Upgrade deployment to unikraft cli Signed-off-by: Dragos Gheorghioiu --- .github/actions/setup-kraftkit/action.yaml | 26 --------- .github/actions/setup-unikraft/action.yaml | 47 ++++++++++++++++ .github/actions/setup-www/action.yaml | 62 +++++++++------------- .github/workflows/main.yaml | 12 ++--- 4 files changed, 79 insertions(+), 68 deletions(-) delete mode 100644 .github/actions/setup-kraftkit/action.yaml create mode 100644 .github/actions/setup-unikraft/action.yaml diff --git a/.github/actions/setup-kraftkit/action.yaml b/.github/actions/setup-kraftkit/action.yaml deleted file mode 100644 index f4872f85..00000000 --- a/.github/actions/setup-kraftkit/action.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: setup-kraftkit - -description: Setup KraftKit. - -inputs: - version: - description: KraftKit version to install (use latest to auto-detect). - required: false - default: latest - -runs: - using: composite - steps: - - name: Install - shell: bash - run: | - if [[ -z $(command -v kraft) ]]; then - _VERSION="${{ inputs.version }}" - if [[ -z "${_VERSION}" || "${_VERSION}" == "latest" ]]; then - _VERSION=$(curl -fsSL https://get.kraftkit.sh/latest.txt) - fi - wget -nv -LO kraft.tar.gz https://github.com/unikraft/kraftkit/releases/download/v${_VERSION}/kraft_${_VERSION}_linux_amd64.tar.gz; - tar xzf kraft.tar.gz kraft; - sudo mv kraft /usr/bin/; - rm kraft.tar.gz; - fi diff --git a/.github/actions/setup-unikraft/action.yaml b/.github/actions/setup-unikraft/action.yaml new file mode 100644 index 00000000..eefb4a31 --- /dev/null +++ b/.github/actions/setup-unikraft/action.yaml @@ -0,0 +1,47 @@ +name: setup-unikraft + +description: | + Install the Unikraft CLI and configure a profile for Unikraft Cloud. + +inputs: + token: + required: true + description: Unikraft Cloud API token. + metro: + required: true + description: Unikraft Cloud metro endpoint (e.g. https://api.dal2.unikraft.cloud). + profile: + required: false + default: oss-www + description: Name of the CLI profile to configure and activate. + version: + required: false + default: latest + description: Unikraft CLI version to install. + +runs: + using: composite + steps: + - name: Install Unikraft CLI + uses: unikraft/setup-action@v1 + with: + version: ${{ inputs.version }} + + - name: Configure profile + shell: bash + env: + UKC_TOKEN: ${{ inputs.token }} + UKC_METRO: ${{ inputs.metro }} + PROFILE: ${{ inputs.profile }} + run: | + mkdir -p "$HOME/.config/unikraft" + cat > "$HOME/.config/unikraft/config.yaml" << EOF + profile: ${PROFILE} + profiles: + ${PROFILE}: + type: cloud + token: ${UKC_TOKEN} + metros: + - name: ${PROFILE} + endpoint: ${UKC_METRO} + EOF diff --git a/.github/actions/setup-www/action.yaml b/.github/actions/setup-www/action.yaml index 776b9cb8..99cbf860 100644 --- a/.github/actions/setup-www/action.yaml +++ b/.github/actions/setup-www/action.yaml @@ -13,25 +13,14 @@ inputs: domain: required: false description: The domain to use for the deployment. - metro: - required: false - description: Unikraft Cloud Metro. - default: http://api.dal2.unikraft.cloud/v1 memory: required: false description: Set the memory size. - default: 1536Mi - args: - required: false - description: Optional arguments you pass to kraft cloud deploy. + default: 1536M port: required: false description: The port the service listens on. default: "3000" - log-level: - required: false - default: error - description: Set the logging level. outputs: domain: @@ -58,39 +47,39 @@ runs: set -e; # Create the service if it does not exist. - _SVC=$(kraft cloud --metro "${{ inputs.metro }}" service get "${{ inputs.name }}" -o raw | jq -r '.data.service_groups[].error') - if [[ "${_SVC}" == "8" ]]; then - if [[ "${{ inputs.domain }}" == "" ]]; then - kraft cloud --metro "${{ inputs.metro }}" service create \ - --subdomain "${{ inputs.name }}" \ - --name "${{ inputs.name }}" \ - "443:${{ inputs.port }}" \ - ; - else - kraft cloud --metro "${{ inputs.metro }}" service create \ - --domain "${{ inputs.domain }}" \ - --name "${{ inputs.name }}" \ - "443:${{ inputs.port }}" \ - ; - fi + if ! unikraft service get "${{ inputs.name }}" -o quiet 2>/dev/null; then + unikraft service create \ + --domains "${{ inputs.domain || inputs.name }}" \ + --name "${{ inputs.name }}" \ + --services "443:${{ inputs.port }}/http+tls" \ + ; fi # Save the generated domain as an output variable - echo "domain=$(kraft cloud --metro ${{ inputs.metro }} service get ${{ inputs.name }} -o raw | jq -r '.data.service_groups[0].domains[0].fqdn')" >> $GITHUB_OUTPUT + echo "domain=$(unikraft service get ${{ inputs.name }} -o json | jq -r '.[0].domains[0].fqdn')" >> $GITHUB_OUTPUT - name: Deploy id: deploy shell: bash run: | - kraft cloud deploy \ - --rollout remove \ - --rollout-qualifier all \ + unikraft build \ + --output "oci://internal/${{ inputs.name }}:latest" \ + .; + + # Remove any existing instance(s) on this service before running the + # new one, so the service always ends up with just the latest build. + unikraft instance delete \ + --filter "service.name==${{ inputs.name }}" \ + --force \ + 2>/dev/null || true; + + unikraft run \ + --autostart \ + --restart always \ --memory "${{ inputs.memory }}" \ --service "${{ inputs.name }}" \ - --image "${{ inputs.name }}" \ - --as kraftfile-runtime \ - ${{ inputs.args }} \ - .; + --image "internal/${{ inputs.name }}:latest" \ + ; - name: Test liveliness id: liveliness @@ -104,7 +93,8 @@ runs: if: ${{ steps.liveliness.outcome == 'failure' }} shell: bash run: | - kraft cloud service logs "${{ inputs.name }}" + _INST=$(unikraft service get "${{ inputs.name }}" -o json | jq -r '.[0].instances[0].name') + unikraft instance logs "${_INST}" exit 1 - name: Update Deployment diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d0709747..bdc9e949 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -12,8 +12,7 @@ on: env: UKC_TOKEN: ${{ secrets.UKC_TOKEN }} UKC_METRO: ${{ secrets.UKC_METRO }} - KRAFTKIT_LOG_LEVEL: debug - KRAFTKIT_NO_CHECK_UPDATES: "true" + UNIKRAFT_LOG_LEVEL: debug permissions: deployments: write @@ -38,8 +37,11 @@ jobs: exit 1 fi - - name: Setup KraftKit - uses: ./.github/actions/setup-kraftkit + - name: Setup Unikraft CLI + uses: ./.github/actions/setup-unikraft + with: + token: ${{ secrets.UKC_TOKEN }} + metro: ${{ secrets.UKC_METRO }} - name: Setup OSS docs website id: www @@ -49,8 +51,6 @@ jobs: environment: main name: oss-www domain: unikraft.org - metro: ${{ secrets.UKC_METRO }} - log-level: trace - uses: chrnorm/deployment-action@v2 name: Create GitHub deployment