From 5ea9fbc26260c6c4c4a5509a16bcc8e5ab91c939 Mon Sep 17 00:00:00 2001 From: ypoplavs Date: Mon, 20 May 2024 14:40:40 +0300 Subject: [PATCH] add building of postam image for nodejs --- .github/workflows/docker-build-develop.yaml | 82 ++++++++++++++--- .../postman/build/agent/Dockerfile.node21 | 20 ++++ ...r-docker-build-executor-postman-node21.yml | 92 +++++++++++++++++++ 3 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 contrib/executor/postman/build/agent/Dockerfile.node21 create mode 100644 goreleaser_files/.goreleaser-docker-build-executor-postman-node21.yml diff --git a/.github/workflows/docker-build-develop.yaml b/.github/workflows/docker-build-develop.yaml index cd81bc5a4ed..326cdf6a5cd 100644 --- a/.github/workflows/docker-build-develop.yaml +++ b/.github/workflows/docker-build-develop.yaml @@ -3,6 +3,7 @@ on: push: branches: - develop + - feat/TKC-1987-postman-image paths-ignore: - 'docs/**' env: @@ -654,21 +655,80 @@ jobs: run: | docker push kubeshop/testkube-playwright-executor:${{ steps.commit.outputs.short }} - workflow_dispatch: - needs: [api, single_executor, executor_jmeter, executor_jmeterd, jmeterd_slave, executor_maven, executor_gradle, executor_cypress, executor_playwright] + executor_postman_node21: runs-on: ubuntu-latest steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: false + - name: Checkout uses: actions/checkout@v4 - - name: Get commit sha - id: github_sha - run: echo "::set-output name=sha_short::${GITHUB_SHA::7}" + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Set-up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: false + + - name: Go Cache + uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: playwright-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - id: commit + uses: prompt/actions-commit-hash@v3 - - name: Repository Dispatch - uses: peter-evans/repository-dispatch@v3 + - name: Release + uses: goreleaser/goreleaser-action@v5 with: - token: ${{ secrets.CI_BOT_TOKEN }} - repository: kubeshop/helm-charts - event-type: trigger-workflow-api-develop - client-payload: '{"image_tag_api": "${{ steps.github_sha.outputs.sha_short }}"}' + distribution: goreleaser + version: latest + args: release -f goreleaser_files/.goreleaser-docker-build-executor-postman-node21.yml --snapshot + env: + GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + DOCKER_BUILDX_BUILDER: "${{ steps.buildx.outputs.name }}" + DOCKER_BUILDX_CACHE_FROM: "type=gha" + DOCKER_BUILDX_CACHE_TO: "type=gha,mode=max" + IMAGE_TAG_SHA: true + + - name: Push image to the Registry + run: | + docker push kubeshop/testkube-postman-executor:node21-${{ steps.commit.outputs.short }} + +# workflow_dispatch: +# needs: [api, single_executor, executor_jmeter, executor_jmeterd, jmeterd_slave, executor_maven, executor_gradle, executor_cypress, executor_playwright] +# runs-on: ubuntu-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v4 +# +# - name: Get commit sha +# id: github_sha +# run: echo "::set-output name=sha_short::${GITHUB_SHA::7}" +# +# - name: Repository Dispatch +# uses: peter-evans/repository-dispatch@v3 +# with: +# token: ${{ secrets.CI_BOT_TOKEN }} +# repository: kubeshop/helm-charts +# event-type: trigger-workflow-api-develop +# client-payload: '{"image_tag_api": "${{ steps.github_sha.outputs.sha_short }}"}' diff --git a/contrib/executor/postman/build/agent/Dockerfile.node21 b/contrib/executor/postman/build/agent/Dockerfile.node21 new file mode 100644 index 00000000000..352de8cbfbd --- /dev/null +++ b/contrib/executor/postman/build/agent/Dockerfile.node21 @@ -0,0 +1,20 @@ +# syntax=docker/dockerfile:1 +FROM node:21-alpine3.17 + +COPY postman /bin/runner +RUN npm install -g newman +RUN apk --no-cache add ca-certificates git curl + +# support npm report permissions +RUN mkdir -p /.npm +RUN chmod 777 /.npm +RUN chmod 777 /root/ +RUN chmod 777 /usr/local/lib/node_modules +RUN chmod 777 /usr/local/bin + +WORKDIR /root/ +EXPOSE 8082 + +USER 1001 + +ENTRYPOINT ["/bin/runner"] \ No newline at end of file diff --git a/goreleaser_files/.goreleaser-docker-build-executor-postman-node21.yml b/goreleaser_files/.goreleaser-docker-build-executor-postman-node21.yml new file mode 100644 index 00000000000..488080a17bc --- /dev/null +++ b/goreleaser_files/.goreleaser-docker-build-executor-postman-node21.yml @@ -0,0 +1,92 @@ +env: + # Goreleaser always uses the docker buildx builder with name "default"; see + # https://github.com/goreleaser/goreleaser/pull/3199 + # To use a builder other than "default", set this variable. + # Necessary for, e.g., GitHub actions cache integration. + - DOCKER_REPO={{ if index .Env "DOCKER_REPO" }}{{ .Env.DOCKER_REPO }}{{ else }}kubeshop{{ end }} + - DOCKER_BUILDX_BUILDER={{ if index .Env "DOCKER_BUILDX_BUILDER" }}{{ .Env.DOCKER_BUILDX_BUILDER }}{{ else }}default{{ end }} + # Setup to enable Docker to use, e.g., the GitHub actions cache; see + # https://docs.docker.com/build/building/cache/backends/ + # https://github.com/moby/buildkit#export-cache + - DOCKER_BUILDX_CACHE_FROM={{ if index .Env "DOCKER_BUILDX_CACHE_FROM" }}{{ .Env.DOCKER_BUILDX_CACHE_FROM }}{{ else }}type=registry{{ end }} + - DOCKER_BUILDX_CACHE_TO={{ if index .Env "DOCKER_BUILDX_CACHE_TO" }}{{ .Env.DOCKER_BUILDX_CACHE_TO }}{{ else }}type=inline{{ end }} + # Build image with commit sha tag + - IMAGE_TAG_SHA={{ if index .Env "IMAGE_TAG_SHA" }}{{ .Env.IMAGE_TAG_SHA }}{{ else }}{{ end }} +builds: + - id: "linux" + main: "./contrib/executor/postman/cmd/agent" + binary: "postman" + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + mod_timestamp: "{{ .CommitTimestamp }}" +dockers: + - dockerfile: "./contrib/executor/postman/build/agent/Dockerfile.node21" + use: buildx + goos: linux + goarch: amd64 + image_templates: + - "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21-amd64{{ end }}" + - "{{ if .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:node21-{{ .ShortCommit }}-amd64{{ end }}" + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.created={{ .Date}}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--builder={{ .Env.DOCKER_BUILDX_BUILDER }}" + - "--cache-to={{ .Env.DOCKER_BUILDX_CACHE_TO }}" + - "--cache-from={{ .Env.DOCKER_BUILDX_CACHE_FROM }}" + - "--build-arg=TOKEN={{ .Env.GITHUB_TOKEN }}" + - "--build-arg=ALPINE_IMAGE={{ .Env.ALPINE_IMAGE }}" + - "--build-arg=BUSYBOX_IMAGE={{ .Env.BUSYBOX_IMAGE }}" + + - dockerfile: "./contrib/executor/postman/build/agent/Dockerfile.node21" + use: buildx + goos: linux + goarch: arm64 + image_templates: + - "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21-arm64v8{{ end }}" + - "{{ if .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:node21-{{ .ShortCommit }}-arm64v8{{ end }}" + build_flag_templates: + - "--platform=linux/arm64/v8" + - "--label=org.opencontainers.image.created={{ .Date }}" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--builder={{ .Env.DOCKER_BUILDX_BUILDER }}" + - "--cache-to={{ .Env.DOCKER_BUILDX_CACHE_TO }}" + - "--cache-from={{ .Env.DOCKER_BUILDX_CACHE_FROM }}" + - "--build-arg=TOKEN={{ .Env.GITHUB_TOKEN }}" + - "--build-arg=ALPINE_IMAGE={{ .Env.ALPINE_IMAGE }}" + - "--build-arg=BUSYBOX_IMAGE={{ .Env.BUSYBOX_IMAGE }}" + +docker_manifests: + - name_template: "{{ if .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:node21-{{ .ShortCommit }}{{ end }}" + image_templates: + - "{{ if .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:node21-{{ .ShortCommit }}-arm64v8{{ end }}" + - "{{ if .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:node21-{{ .ShortCommit }}-amd64{{ end }}" + - name_template: "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21{{ end }}" + image_templates: + - "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21-amd64{{ end }}" + - "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21-arm64v8{{ end }}" + - name_template: "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:node21{{ end }}" + image_templates: + - "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21-amd64{{ end }}" + - "{{ if not .Env.IMAGE_TAG_SHA }}{{ .Env.DOCKER_REPO }}/testkube-postman-executor:{{ .Version }}-node21-arm64v8{{ end }}" + +release: + disable: true + +docker_signs: + - cmd: cosign + artifacts: all + output: true + args: + - 'sign' + - '${artifact}' + - "--yes"