This is an automated email from the ASF dual-hosted git repository. sciabarracom pushed a commit to branch 0.9.0 in repository https://gitbox.apache.org/repos/asf/openserverless-devcontainer.git
commit 0d26d549047c9176852eee89a9b73c7790ca30c0 Author: Michele Sciabarra <[email protected]> AuthorDate: Fri Sep 4 19:42:16 2026 +0200 reworked build --- .env.dist | 13 ++++ .github/workflows/check.yml | 40 +++++++++++ .github/workflows/image.yml | 94 ++++++++++++++++++++++++++ .github/workflows/images.yml | 63 ------------------ .gitignore | 1 + Dockerfile | 3 + Taskfile.yml | 153 ++++++++++++++++++++++++++++++++++++++----- 7 files changed, 286 insertions(+), 81 deletions(-) diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..4681e43 --- /dev/null +++ b/.env.dist @@ -0,0 +1,13 @@ +# github user, used to derive the default local image name +GITHUB_USER=github: put here your github user + +# full image name WITHOUT the tag (registry/namespace/repository). +# Overrides the default taken from ARG DEVCONTAINER_IMAGE_DEFAULT in the Dockerfile. +MY_DEVCONTAINER_IMAGE=ghcr.io/${GITHUB_USER}/openserverless-devcontainer + +# for task docker-login-ghcr (github) +GITHUB_TOKEN= + +# for task docker-login-dockerhub (dockerhub) +DOCKERHUB_TOKEN= +DOCKERHUB_USER= diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..763789c --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +name: Check +on: + push: + pull_request: + workflow_dispatch: + +jobs: + check: + name: Check OpenServerless Devcontainer + runs-on: ubuntu-22.04 + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + submodules: recursive + - name: Setup + run: | + sudo sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin + # the image is built (not pushed) to verify the Dockerfile still works + - name: Build + run: task build diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml new file mode 100644 index 0000000..f88ddcd --- /dev/null +++ b/.github/workflows/image.yml @@ -0,0 +1,94 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +name: Build Image +on: + push: + tags: + - '[0-9]*' + branches-ignore: '*' + workflow_dispatch: + +jobs: + image: + name: Build OpenServerless Devcontainer Image + runs-on: ubuntu-22.04 + permissions: + contents: write + packages: write + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + submodules: recursive + # full history and tags: "task tag" replaces the existing tags + # and "git describe" needs them to be present + fetch-depth: 0 + - name: Setup + run: | + sudo sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin + # Manual run: create a new snapshot tag on the current HEAD and push it. + # The push of the tag does not start another run (GITHUB_TOKEN pushes do + # not trigger workflows), so this same run goes on and builds it. + - name: Tag HEAD (manual run) + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + task tag + task ci + - name: Assign TAG from push + run: | + echo "IMG_TAG=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV" + - name: Generate .env + run: | + OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') + if [ "$OWNER" = "apache" ]; then + IMAGE=$(awk -F= '/ARG DEVCONTAINER_IMAGE_DEFAULT=/ { print $2 ; exit }' Dockerfile) + else + IMAGE="ghcr.io/$OWNER/openserverless-devcontainer" + fi + echo "GITHUB_USER=$OWNER" > .env + echo "MY_DEVCONTAINER_IMAGE=$IMAGE" >> .env + cat .env + - name: Select registry + env: + DOCKERHUB_REGISTRY: ${{ secrets.DOCKERHUB_REGISTRY }} + run: | + if [ -n "$DOCKERHUB_REGISTRY" ]; then + REGISTRY="$DOCKERHUB_REGISTRY" + elif [ "${{ github.repository_owner }}" = "apache" ]; then + REGISTRY="docker.io" + else + REGISTRY="ghcr.io" + fi + echo "REGISTRY=$REGISTRY" >> "$GITHUB_ENV" + - name: Registry login + uses: docker/login-action@v4 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKERHUB_USER || github.repository_owner }} + password: ${{ secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v4 + with: + image: tonistiigi/binfmt:qemu-v7.0.0-28 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Image + run: task buildx PUSH=1 DEVCONTAINER_TAG=$IMG_TAG + diff --git a/.github/workflows/images.yml b/.github/workflows/images.yml deleted file mode 100644 index ccf74f4..0000000 --- a/.github/workflows/images.yml +++ /dev/null @@ -1,63 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -name: Build Images -on: - push: - tags: - - '[0-9]*' - branches-ignore: '*' - #pull_request: - # branches: [main] - -permissions: - contents: write - packages: write - -jobs: - image: - name: Build Image - runs-on: ubuntu-22.04 - steps: - - name: Checkout recursive - uses: actions/checkout@v2 - # TODO - #- name: License check - # uses: apache/skywalking-eyes@main - # continue-on-error: true - - name: Assign TAG from pull request - if: ${{ github.event_name == 'pull_request' }} - run: | - echo "IMG_TAG=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV" - - name: Assign TAG from push - if: ${{ github.event_name != 'pull_request' }} - run: | - echo "IMG_TAG=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV" - - name: Registry login - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build and push - uses: docker/build-push-action@v5 - with: - platforms: linux/amd64,linux/arm64 - tags: apache/openserverless-devcontainer:${{ env.IMG_TAG }} - push: true - diff --git a/.gitignore b/.gitignore index e60aaea..febe6bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ _* +.env diff --git a/Dockerfile b/Dockerfile index fd0d4b3..0150a6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ FROM node:22 + +ARG DEVCONTAINER_IMAGE_DEFAULT=docker.io/apache/openserverless-devcontainer +ARG DEVCONTAINER_TAG_DEFAULT=latest # Install basic development tools RUN \ echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ diff --git a/Taskfile.yml b/Taskfile.yml index 504a420..4b54c00 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,46 +1,163 @@ -version: 3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +version: '3' vars: - - NAME: apache/openserverless-devcontainer + BASETAG: 0.9.0-incubating + SUFFIX: "-SNAPSHOT" + COMMIT_ID: + sh: git rev-parse --short HEAD + # taken from the tag - overridable with DEVCONTAINER_TAG env var TAG: - sh: git tag --sort=-creatordate | head -n 1 || "latest" + sh: echo "${DEVCONTAINER_TAG:-$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD)}" + # taken from the Dockerfile - overridable with MY_DEVCONTAINER_IMAGE env var + DEVCONTAINER_IMAGE: + sh: echo "${MY_DEVCONTAINER_IMAGE:-$(awk -F= '/ARG DEVCONTAINER_IMAGE_DEFAULT=/ { print $2 ; exit }' Dockerfile)}" + +dotenv: + - .env tasks: default: task --list-all - show: "echo {{.NAME}}:{{.TAG}}" + image: + desc: | + Print the image name that would be built. + silent: true + cmds: + - echo "Devcontainer=${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}:{{.TAG}}" - update-opsroot: + show: silent: true cmds: - - jq . ../olaris/opsroot.json >_opsroot.orig - - jq '.config.images.devcontainer = "{{.NAME}}:{{.TAG}}"' ../olaris/opsroot.json >_opsroot.json - - diff _opsroot.orig _opsroot.json || cp -v _opsroot.json ../olaris/opsroot.json + - echo "${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}:{{.TAG}}" + + docker-login-ghcr: + silent: true + cmds: + - | + echo "Logging in to ghcr.io as $GITHUB_USER" + echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USER --password-stdin + docker-login-dockerhub: + silent: true + cmds: + - | + echo "Logging in to docker.io as $DOCKERHUB_USER" + echo $DOCKERHUB_TOKEN | docker login docker.io -u $DOCKERHUB_USER --password-stdin + + docker-login: + desc: | + Login to the registry the image name points to: docker.io for apache images, + ghcr.io otherwise. + silent: true + cmds: + - | + IMG="${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}" + case "$IMG" in + ghcr.io/*) task docker-login-ghcr ;; + *) task docker-login-dockerhub ;; + esac + + # deprecated - use task tag image-tag: - - git tag -d "$(git tag)" || true - - git tag "0.1.0-incubating.$(date +%y%m%d%H%M)" - - echo {{.NAME}}:$(git tag --sort=-creatordate | head -n 1) + desc: "[deprecated] use task tag" + silent: true + cmds: + - 'echo "deprecated, use task tag"' + + tag: + desc: | + Create a new snapshot tag for the current git commit. + NOTE: this deletes the existing local tags first - snapshot tags are disposable. + silent: true + vars: + TS: + sh: date '+%y %m %d %H %M' | awk '{printf "%s%s%d%s%d\n", $1, substr("abcdefghijkl",$2+0,1), $3, substr("abcdefghijklmnopqrstuvwx",$4+1,1), $5}' + cmds: + - git tag -d $(git tag) 2>/dev/null || true + - | + TAG="{{.BASETAG}}.{{.TS}}{{.SUFFIX}}" + git tag -f $TAG + echo New tag $TAG + + ci: + desc: | + Push the tags, starting the GitHub Actions build on the repo that received them. + This does not build anything locally. + cmds: + - git push --tags --force + + buildx: + desc: | + Build the docker image using buildx. Set PUSH=1 to push the image to the registry. + silent: true + cmds: + - | + IMG="${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}:{{.TAG}}" + if [ -n "{{.PUSH}}" ]; then + {{.DRY}} docker buildx build -t "$IMG" \ + --build-arg DEVCONTAINER_IMAGE_DEFAULT="${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}" \ + --build-arg DEVCONTAINER_TAG_DEFAULT="{{.TAG}}" \ + --platform linux/amd64,linux/arm64 . --push + else + {{.DRY}} docker buildx build -t "$IMG" \ + --build-arg DEVCONTAINER_IMAGE_DEFAULT="${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}" \ + --build-arg DEVCONTAINER_TAG_DEFAULT="{{.TAG}}" \ + . --load + fi + echo "Built $IMG" build: - - docker build -t "{{.NAME}}:{{.TAG}}" . --load - - task: show + desc: | + Build the docker image locally and load it into the local docker daemon. + cmds: + - task: buildx + + update-opsroot: + desc: update the devcontainer image in olaris/opsroot.json + silent: true + cmds: + - jq . ../olaris/opsroot.json >_opsroot.orig + - | + IMG="${MY_DEVCONTAINER_IMAGE:-{{.DEVCONTAINER_IMAGE}}}:{{.TAG}}" + jq --arg img "$IMG" '.config.images.devcontainer = $img' ../olaris/opsroot.json >_opsroot.json + - diff _opsroot.orig _opsroot.json || cp -v _opsroot.json ../olaris/opsroot.json clean: + desc: remove the local containers and images + cmds: - docker rm -f ssh-devcontainer || true - docker images | awk '/<none>|devcontainer/{print $3}' | xargs docker rmi -f || true all: - - task: image-tag + desc: tag, build and update opsroot + cmds: + - task: tag # warning: the ':' is missing intentionally to reload the tag - task build - task update-opsroot publish: + desc: commit, tag and push - this starts the CI build + cmds: - git commit -m "publishing $(date)" -a || true - - task: image-tag + - task: tag - task update-opsroot - - git push origin main --tags - + - task: ci
