diff --git a/.github/workflows/build-devcontainer-image.yml b/.github/workflows/build-devcontainer-image.yml new file mode 100644 index 00000000000..c10e1543363 --- /dev/null +++ b/.github/workflows/build-devcontainer-image.yml @@ -0,0 +1,49 @@ +name: Build Devcontainer image +on: + workflow_dispatch: + # no content, allows manual triggering + + schedule: + # 5:30 pm every Sunday (UTC) + # to pick up any important bug fixes etc in base image + - cron: '30 17 * * 0' + + push: + # run when changes pushed to master if any devcontainer files changed + branches: + - master + paths: + - .devcontainer/** + +jobs: + # Based on: https://docs.github.com/en/actions/guides/publishing-docker-images#publishing-images-to-github-packages + build-devcontainer-image: + runs-on: ubuntu-latest + + permissions: + packages: write + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: 'true' + + - name: Log in to GitHub Docker Registry + uses: docker/login-action@v1 + with: + registry: docker.pkg.github.com + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN } + + - name: Build & push Devcontainer image + uses: docker/build-push-action@v2 + with: + context: .devcontainer + push: true + # Build an image usable as cache-from, per: https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources + build-args: BUILDKIT_INLINE_CACHE=1 + tags: | + docker.pkg.github.com/${{ github.repository }}/devcontainer:latest + docker.pkg.github.com/${{ github.repository }}/devcontainer:${{ github.sha }} diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 51011246860..77715e6739d 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -44,8 +44,30 @@ jobs: run: | docker buildx build --tag devcontainer:1.0 --cache-from=type=local,src=docker-cache --load .devcontainer + - name: Run devcontainer image + id: devcontainer + run: | + container_id=$(docker create -w /workspace -v $GITHUB_WORKSPACE:/workspace -v /var/run/docker.sock:/var/run/docker.sock devcontainer:1.0) + docker start "$container_id" + echo "::set-output name=id::$container_id" + - name: Run CI tasks - run: docker run -w /workspace -v $GITHUB_WORKSPACE:/workspace -e AZURE_TENANT_ID -e AZURE_CLIENT_ID -e AZURE_CLIENT_SECRET -e AZURE_SUBSCRIPTION_ID devcontainer:1.0 task ci + run: | + docker exec "${{steps.devcontainer.outputs.id}}" task ci + + - name: Build docker image + run: | + container_id=${{steps.devcontainer.outputs.id}} + docker exec "$container_id" task controller:docker-build + docker cp "$container_id:/workspace/hack/generated/bin" . + mv bin/*.tar azure-service-operator.tar + + - name: Archive Docker image + uses: actions/upload-artifact@v2 + with: + name: controller-image + path: azure-service-operator.tar + if-no-files-found: error - name: Upload code coverage to Codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/Taskfile.yml b/Taskfile.yml index 06b10ceaa3b..b23d79740b0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -180,6 +180,7 @@ tasks: - Dockerfile cmds: - docker build . -t {{.CONTROLLER_DOCKER_IMAGE}} + - docker save {{.CONTROLLER_DOCKER_IMAGE}} > bin/{{.CONTROLLER_DOCKER_IMAGE}}.tar controller:test-integration-envtest: desc: Run integration tests with envtest using record/replay.