This is an automated email from the ASF dual-hosted git repository. sciabarracom pushed a commit to tag 0.9.0-incubating.26i4q2-SNAPSHOT in repository https://gitbox.apache.org/repos/asf/openserverless-streamer.git
commit 536b711da613e85c4308b5b2e3d8c0bd68631c94 Author: Michele Sciabarra <[email protected]> AuthorDate: Fri Sep 4 16:01:56 2026 +0200 updated task and build --- .env.dist | 18 +++++++ .github/workflows/check.yml | 6 +-- .github/workflows/image.yml | 38 +++++++++++---- Dockerfile | 2 + README.md | 76 ++---------------------------- Taskfile.yml | 112 ++++++++++++++++++++++++++------------------ 6 files changed, 122 insertions(+), 130 deletions(-) diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..8027a41 --- /dev/null +++ b/.env.dist @@ -0,0 +1,18 @@ +# 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 STREAMER_IMAGE_DEFAULT in the Dockerfile. +MY_STREAMER_IMAGE=ghcr.io/${GITHUB_USER}/openserverless-streamer + +# for task docker-login-ghcr (github) +GITHUB_TOKEN= + +# for task docker-login-dockerhub (dockerhub) +DOCKERHUB_TOKEN= +DOCKERHUB_USER= + +# used to run the streamer locally +OW_APIHOST= +STREAMER_ADDR= +HTTP_SERVER_PORT= diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index f95c00e..9cc57a6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,11 +29,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: submodules: recursive - - name: License - uses: apache/skywalking-eyes@main + - name: License + uses: apache/[email protected] - name: Assign TAG from pull request if: ${{ github.event_name == 'pull_request' }} run: | diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 1599ab0..9ee1ca2 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -34,13 +34,13 @@ jobs: sudo rm -rf /usr/share/dotnet sudo rm -rf "$AGENT_TOOLSDIRECTORY" - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: submodules: recursive - name: Setup run: bash .github/cisetup.sh - name: License - uses: apache/skywalking-eyes@main + uses: apache/[email protected] - name: Assign TAG from pull request if: ${{ github.event_name == 'pull_request' }} run: | @@ -49,15 +49,38 @@ jobs: if: ${{ github.event_name != 'pull_request' }} 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 STREAMER_IMAGE_DEFAULT=/ { print $2 ; exit }' Dockerfile) + else + IMAGE="ghcr.io/$OWNER/openserverless-streamer" + fi + echo "GITHUB_USER=$OWNER" > .env + echo "MY_STREAMER_IMAGE=$IMAGE" >> .env + cat .env - name: Unit Test run: task test continue-on-error: false + - 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@v3 with: - registry: registry.hub.docker.com - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + 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@v3 with: @@ -65,7 +88,4 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Image - env: - REGISTRY: apache - NAMESPACE: apache - run: task buildx PUSH=1 TAG=$IMG_TAG \ No newline at end of file + run: task buildx PUSH=1 STREAMER_TAG=$IMG_TAG \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e468671..bad9729 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ ENV CGO_ENABLED=0 GOOS=linux RUN go build -ldflags="-s -w" -o streamer FROM scratch +ARG STREAMER_IMAGE_DEFAULT=docker.io/apache/openserverless-streamer +ARG STREAMER_TAG_DEFAULT=latest COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /src/streamer /streamer ENTRYPOINT ["/streamer"] diff --git a/README.md b/README.md index c5a80a3..151ae25 100644 --- a/README.md +++ b/README.md @@ -61,77 +61,7 @@ given namespace, default package, and action name. - `GET/POST /web/{namespace}/{package}/{action}`: to invoke an OpenWhisk web action on the given namespace, custom package, and action name. -## Tasks - -Taskfile supports the following tasks: - -```yaml -* build: Build the streamer binary locally. This will create a binary named streamer in the current directory. -* buildx: Build the docker image using buildx. Set PUSH=1 to push the image to the registry. -* clean: Clean up the build artifacts. This will remove the streamer binary and clean the go cache. -* docker-login: Login to the docker registry. Set REGISTRY=ghcr or REGISTRY=dockerhub in .env to use the respective registry. -* image-tag: Create a new tag for the current git commit. -* run: Run the streamer binary locally, using configuration from .env file -* test: Run the tests in the src directory. -``` - -## Build and push - -### Private registry or local image - -To build an image and push it on a private repository, firstly choose which -registry you want to use. -Tasks support is for Github (ghcr) and Dockerhub (dockerhub). -So copy the `.env.example` to `.env` and configure the required variables for -authentication and set the `REGISTRY` and `NAMESPACE` accordly. - -Now create a new tag - -```bash -$ task image-tag -``` -You should see an output like this: - -```bash -Deleted tag '0.1.0-rc1-incubating.2504260711' (was 5a2f6d3) -0.1.0-rc1-incubating.2504260905 -``` - -:bulb: **NOTE** If you leave unset `REGISTRY` a local `openserverless-streamer` -image will be built, using the generated tag. - -If you setup the `REGISTRY` and `NAMESPACE`, you can give a: - -```bash -$ task docker-login -``` - -To build: - -```bash -$ task buildx -``` - -To build and push - -```bash -$ task buildx PUSH=1 -``` - -### Apache repository -To build an official Apache OpensSrverless Streamer image, you -need to be a committer. - -If you have the proper permissions, the build process will start pushing a -new tag to apache/openserverless-streamer repository. -So, for example, if your tag is `0.1.0-rc1-incubating.2504260905` and your -git remote is `apache` - -```bash -$ git push apache 0.1.0-rc1-incubating.2504260905 -``` - -This will trigger the build workflow, and the process will be visible at -https://github.com/apache/openserverless-streamer/actions - +## Building +Check the [BUILD.md](https://github.com/apache/openserverless/blob/main/BUILD.md) +in the [apache/openserverless](https://github.com/apache/openserverless) repository. diff --git a/Taskfile.yml b/Taskfile.yml index b6ae333..3be89cc 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -18,88 +18,104 @@ version: "3" vars: - BASETAG: 0.1.0-incubating + BASETAG: 0.9.0-incubating + SUFFIX: "-SNAPSHOT" COMMIT_ID: sh: git rev-parse --short HEAD + # taken from the tag - overridable with STREAMER_TAG env var TAG: - sh: git describe --tags --abbrev=0 2>/dev/null || echo latest + sh: echo "${STREAMER_TAG:-$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD)}" + # taken from the Dockerfile - overridable with MY_STREAMER_IMAGE env var + STREAMER_IMAGE: + sh: echo "${MY_STREAMER_IMAGE:-$(awk -F= '/ARG STREAMER_IMAGE_DEFAULT=/ { print $2 ; exit }' Dockerfile)}" dotenv: - .env tasks: - docker-login-ghcr: > + docker-login-ghcr: silent: true - cmds: + 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: + cmds: - | - echo "Logging in to dockerhub as $DOCKERHUB_USER" - echo $DOCKERHUB_TOKEN | docker login -u $DOCKERHUB_USER --password-stdin + 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 docker registry. Set REGISTRY=ghcr or REGISTRY=dockerhub in .env - to use the respective registry. + Login to the registry the image name points to: docker.io for apache images, + ghcr.io otherwise. silent: true cmds: - | - if [ -z "$REGISTRY" ]; then - echo "Error: REGISTRY variable is not set in .env" - exit 1 - fi - task docker-login-$REGISTRY - - base-image-name: + IMG="${MY_STREAMER_IMAGE:-{{.STREAMER_IMAGE}}}" + case "$IMG" in + ghcr.io/*) task docker-login-ghcr ;; + *) task docker-login-dockerhub ;; + esac + + image: + desc: | + Print the image name that would be built. silent: true cmds: - - | - if [ -n "$REGISTRY" ] && [ -z "$NAMESPACE" ]; then - echo "Error: NAMESPACE variable is not set in .env" - exit 1 - fi - if [ "$REGISTRY" = "ghcr" ]; then - echo "ghcr.io/$NAMESPACE/openserverless-streamer" - elif [ "$REGISTRY" = "dockerhub" ]; then - echo "docker.io/$NAMESPACE/openserverless-streamer" - elif [ "$REGISTRY" = "apache" ]; then - echo "registry.hub.docker.com/apache/openserverless-streamer" - else - echo "openserverless-streamer" - fi + - echo "Streamer=${MY_STREAMER_IMAGE:-{{.STREAMER_IMAGE}}}:{{.TAG}}" + # deprecated - use task tag image-tag: + 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: | - Create a new tag for the current git commit. + Push the tags, starting the GitHub Actions build on the repo that received them. + This does not build anything locally. cmds: - - git tag -d $(git tag) - - git tag -f {{.BASETAG}}.$(date +%y%m%d%H%M) - - env PAGER= git tag - + - 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: - | - BASEIMG=$(task base-image-name) - IMG="$BASEIMG:{{.TAG}}" + IMG="${MY_STREAMER_IMAGE:-{{.STREAMER_IMAGE}}}:{{.TAG}}" if [ -n "{{.PUSH}}" ]; then - if [ -z "$REGISTRY" ]; then - echo "Error: REGISTRY variable must be set in .env to push the image" - exit 1 - fi - {{.DRY}} docker buildx build -t $IMG --platform linux/amd64,linux/arm64 . --push + {{.DRY}} docker buildx build -t "$IMG" \ + --build-arg STREAMER_IMAGE_DEFAULT="${MY_STREAMER_IMAGE:-{{.STREAMER_IMAGE}}}" \ + --build-arg STREAMER_TAG_DEFAULT="{{.TAG}}" \ + --platform linux/amd64,linux/arm64 . --push else - {{.DRY}} docker buildx build -t $IMG . --load + {{.DRY}} docker buildx build -t "$IMG" \ + --build-arg STREAMER_IMAGE_DEFAULT="${MY_STREAMER_IMAGE:-{{.STREAMER_IMAGE}}}" \ + --build-arg STREAMER_TAG_DEFAULT="{{.TAG}}" \ + . --load fi + echo "Built $IMG" test: desc: | @@ -111,6 +127,12 @@ tasks: cd ../ build: + desc: | + Build the docker image locally and load it into the local docker daemon. + cmds: + - task: buildx + + build-binary: desc: | Build the streamer binary locally. This will create a binary named streamer in the current directory. silent: true @@ -146,6 +168,6 @@ tasks: desc: | Run the streamer binary locally, using configuration from .env file cmds: - - task: build + - task: build-binary - ./streamer
