Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

create a github action to build and publish docker image (#453)

r33drichards237f4ab477ed
diff --git a/.github/workflows/docker-publish-kasm.yml b/.github/workflows/docker-publish-kasm.yml
new file mode 100644
index 0000000000..882d6869b1
--- /dev/null
+++ b/.github/workflows/docker-publish-kasm.yml
@@ -0,0 +1,149 @@
+name: Build and Publish CUA Ubuntu Container
+
+on:
+ push:
+ branches:
+ - main
+ tags:
+ - "docker-kasm-v*.*.*"
+ paths:
+ - "libs/kasm/**"
+ - ".github/workflows/docker-publish-kasm.yml"
+ pull_request:
+ paths:
+ - "libs/kasm/**"
+ - ".github/workflows/docker-publish-kasm.yml"
+
+
+env:
+ IMAGE_NAME: cua-ubuntu
+ DOCKER_HUB_ORG: trycua
+
+jobs:
+ build-and-push:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ platform:
+ - linux/amd64
+ - linux/arm64
+ # todo unsupported base image
+ # - windows/amd64
+ # - darwin/amd64
+ # - darwin/arm64
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Prepare platform tag
+ id: platform
+ run: |
+ # Convert platform (e.g., linux/amd64) to a valid tag suffix (e.g., linux-amd64)
+ PLATFORM_TAG=$(echo "${{ matrix.platform }}" | sed 's/\//-/g')
+ echo "tag=${PLATFORM_TAG}" >> $GITHUB_OUTPUT
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+
+ - name: Log in to Docker Hub
+ uses: docker/login-action@v3
+ with:
+ username: trycua
+ password: ${{ secrets.DOCKER_HUB_TOKEN }}
+
+ - name: Extract metadata (PR)
+ if: github.event_name == 'pull_request'
+ id: meta-pr
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}
+ tags: |
+ type=raw,value=${{ github.sha }}
+
+ - name: Extract metadata (main branch)
+ if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
+ id: meta-main
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}
+ tags: |
+ type=raw,value=latest
+
+ - name: Extract metadata (semantic version tag)
+ if: startsWith(github.ref, 'refs/tags/docker-kasm-v')
+ id: meta-semver
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}
+ tags: |
+ type=semver,pattern={{version}},prefix=docker-kasm-v
+ type=semver,pattern={{major}}.{{minor}},prefix=docker-kasm-v
+ type=semver,pattern={{major}},prefix=docker-kasm-v
+ type=raw,value=latest
+
+ - name: Build and push Docker image (PR)
+ if: github.event_name == 'pull_request'
+ uses: docker/build-push-action@v5
+ with:
+ context: ./libs/kasm
+ file: ./libs/kasm/Dockerfile
+ push: true
+ tags: ${{ steps.meta-pr.outputs.tags }}
+ labels: ${{ steps.meta-pr.outputs.labels }}
+ platforms: ${{ matrix.platform }}
+ cache-from: |
+ type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:buildcache-${{ steps.platform.outputs.tag }}
+ type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:latest
+ cache-to: type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:buildcache-${{ steps.platform.outputs.tag }},mode=max
+
+ - name: Build and push Docker image (main branch)
+ if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
+ uses: docker/build-push-action@v5
+ with:
+ context: ./libs/kasm
+ file: ./libs/kasm/Dockerfile
+ push: true
+ tags: ${{ steps.meta-main.outputs.tags }}
+ labels: ${{ steps.meta-main.outputs.labels }}
+ platforms: ${{ matrix.platform }}
+ cache-from: |
+ type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:buildcache-${{ steps.platform.outputs.tag }}
+ type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:latest
+ cache-to: type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:buildcache-${{ steps.platform.outputs.tag }},mode=max
+
+ - name: Build and push Docker image (semantic version tag)
+ if: startsWith(github.ref, 'refs/tags/docker-kasm-v')
+ uses: docker/build-push-action@v5
+ with:
+ context: ./libs/kasm
+ file: ./libs/kasm/Dockerfile
+ push: true
+ tags: ${{ steps.meta-semver.outputs.tags }}
+ labels: ${{ steps.meta-semver.outputs.labels }}
+ platforms: ${{ matrix.platform }}
+ cache-from: |
+ type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:buildcache-${{ steps.platform.outputs.tag }}
+ type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:latest
+ cache-to: type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.IMAGE_NAME }}:buildcache-${{ steps.platform.outputs.tag }},mode=max
+
+ - name: Image digest
+ if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/docker-kasm-v')
+ run: |
+ if [ "${{ github.event_name }}" == "pull_request" ]; then
+ echo "Image pushed with digest ${{ steps.meta-pr.outputs.digest }}"
+ elif [[ "${{ github.ref }}" == refs/tags/docker-kasm-v* ]]; then
+ echo "Image pushed with digest ${{ steps.meta-semver.outputs.digest }}"
+ else
+ echo "Image pushed with digest ${{ steps.meta-main.outputs.digest }}"
+ fi
+
+ - name: print image tags
+ run: |
+ if [ "${{ github.event_name }}" == "pull_request" ]; then
+ echo "Image tags: ${{ steps.meta-pr.outputs.tags }}"
+ elif [[ "${{ github.ref }}" == refs/tags/docker-kasm-v* ]]; then
+ echo "Image tags: ${{ steps.meta-semver.outputs.tags }}"
+ else
+ echo "Image tags: ${{ steps.meta-main.outputs.tags }}"
+ fi