diff --git a/.github/workflows/build-agents.yml b/.github/workflows/build-agents.yml index a3af104..f302357 100644 --- a/.github/workflows/build-agents.yml +++ b/.github/workflows/build-agents.yml @@ -17,14 +17,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up Go uses: actions/setup-go@v5 with: go-version: 1.21 + - name: Build discovery agent working-directory: . run: | make build-discovery + - name: Build traceability agent working-directory: . run: | diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml index 8f2985c..bbfd7be 100644 --- a/.github/workflows/build-docker-images.yml +++ b/.github/workflows/build-docker-images.yml @@ -21,10 +21,13 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Create commit_id & version environment variables + - name: Set outputs + id: vars run: | - commitId=$(git rev-parse --short HEAD) - echo "commitId=$commitId" >> $GITHUB_ENV + echo "date=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT + echo "tag=${{github.ref_name }}" >> $GITHUB_OUTPUT + echo "sdkversion=$(grep github.com/Axway/agent-sdk go.mod | awk '{print $2}')" >> $GITHUB_OUTPUT + echo "commit=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT - name: Log in to the Container registry uses: docker/login-action@v3 @@ -49,8 +52,11 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - VERSION=${{ github.ref_name }} - COMMIT_ID=${{ env.commitId }} + time=${{ steps.vars.outputs.date }} + CGO_ENABLED=0 + version=${{ steps.vars.outputs.tag }} + sdk_version=${{ steps.vars.outputs.sdkversion }} + commit_id=${{ steps.vars.outputs.commit }} buildTraceabilityAgentDocker: needs: testAgents @@ -63,10 +69,13 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Create commit_id & version environment variables + - name: Set outputs + id: vars run: | - commitId=$(git rev-parse --short HEAD) - echo "commitId=$commitId" >> $GITHUB_ENV + echo "date=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT + echo "tag=${{github.ref_name }}" >> $GITHUB_OUTPUT + echo "sdkversion=$(grep github.com/Axway/agent-sdk go.mod | awk '{print $2}')" >> $GITHUB_OUTPUT + echo "commit=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT - name: Log in to the Container registry uses: docker/login-action@v3 @@ -91,8 +100,11 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - VERSION=${{ github.ref_name }} - COMMIT_ID=${{ env.commitId }} + time=${{ steps.vars.outputs.date }} + CGO_ENABLED=0 + version=${{ steps.vars.outputs.tag }} + sdk_version=${{ steps.vars.outputs.sdkversion }} + commit_id=${{ steps.vars.outputs.commit }} notifyTeamsChannel: runs-on: ubuntu-latest diff --git a/build/discovery.Dockerfile b/build/discovery.Dockerfile index 654a52d..abdf57e 100644 --- a/build/discovery.Dockerfile +++ b/build/discovery.Dockerfile @@ -2,60 +2,53 @@ # golang:1.21.6-alpine3.19 linux/amd64 FROM docker.io/golang@sha256:2523a6f68a0f515fe251aad40b18545155135ca6a5b2e61da8254df9153e3648 AS builder -ARG VERSION -ARG COMMIT_ID +ARG commit_id +ARG version +ARG sdk_version +ARG time +ARG CGO_ENABLED -ENV APP_HOME /go/src/github.com/Axway/agents-webmethods +ENV BASEPATH /go/src/github.com/Axway/agents-webmethods ENV APP_USER axway -ENV AGENT=${APP_HOME}/cmd/discovery - -RUN mkdir -p $APP_HOME -WORKDIR $APP_HOME +RUN mkdir -p ${BASEPATH} +WORKDIR ${BASEPATH} # Copy necessary files COPY . . -RUN export time=`date +%Y%m%d%H%M%S` && \ - export commit_id=${COMMIT_ID} && \ - export version=${VERSION} && \ - export sdk_version=`go list -m github.com/Axway/agent-sdk | awk '{print $2}' | awk -F'-' '{print substr($1, 2)}'` && \ - export GOOS=linux && \ - export CGO_ENABLED=0 && \ - export GOARCH=amd64 && \ +RUN --mount=type=cache,target=/root/.cache/go-build \ go build -tags static_all \ -ldflags="-X 'github.com/Axway/agent-sdk/pkg/cmd.BuildTime=${time}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.BuildVersion=${version}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.BuildCommitSha=${commit_id}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.SDKBuildVersion=${sdk_version}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.BuildAgentName=webMethodsDiscoveryAgent'" \ - -a -o ${APP_HOME}/bin/webmethods_discovery_agent ${AGENT}/main.go + -a -o ${BASEPATH}/bin/webmethods_discovery_agent ${BASEPATH}/cmd/discovery/main.go # Create non-root user -RUN addgroup -g 2500 $APP_USER && adduser -u 2500 -D -G $APP_USER $APP_USER -RUN chown -R $APP_USER:$APP_USER ${APP_HOME}/bin/webmethods_discovery_agent - -USER $APP_USER +RUN addgroup -g 2500 ${APP_USER} && adduser -u 2500 -D -G ${APP_USER} ${APP_USER} +RUN chown -R $APP_USER:$APP_USER ${BASEPATH}/bin/webmethods_discovery_agent +USER ${APP_USER} # alpine 3.19 linux/amd64 FROM docker.io/alpine@sha256:13b7e62e8df80264dbb747995705a986aa530415763a6c58f84a3ca8af9a5bcd +ENV BASEPATH /go/src/github.com/Axway/agents-webmethods ENV APP_USER axway -ENV APP_HOME /go/src/github.com/Axway/agents-webmethods # Copy binary, user, config file and certs from previous build step COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder $APP_HOME/build/webmethods_discovery_agent.yml /webmethods_discovery_agent.yml -COPY --from=builder ${APP_HOME}/bin/webmethods_discovery_agent /webmethods_discovery_agent +COPY --from=builder ${BASEPATH}/bin/webmethods_discovery_agent /webmethods_discovery_agent +COPY build/webmethods_discovery_agent.yml /webmethods_discovery_agent.yml RUN mkdir /keys && \ chown -R axway /keys && \ apk --no-cache add openssl libssl3 libcrypto3 musl musl-utils libc6-compat busybox curl && \ find / -perm /6000 -type f -exec chmod a-s {} \; || true - -USER $APP_USER +USER ${APP_USER} VOLUME ["/keys"] HEALTHCHECK --retries=1 CMD curl --fail http://localhost:${STATUS_PORT:-8989}/status || exit 1 ENTRYPOINT ["/webmethods_discovery_agent"] diff --git a/build/traceability.Dockerfile b/build/traceability.Dockerfile index 32d7b98..55060a8 100644 --- a/build/traceability.Dockerfile +++ b/build/traceability.Dockerfile @@ -1,61 +1,54 @@ # Build image # golang:1.21.6-alpine3.19 linux/amd64 FROM docker.io/golang@sha256:2523a6f68a0f515fe251aad40b18545155135ca6a5b2e61da8254df9153e3648 AS builder -ENV APP_HOME /go/src/github.com/Axway/agents-webmethods -ENV APP_USER axway -ENV AGENT=${APP_HOME}/cmd/traceability -ARG VERSION -ARG COMMIT_ID +ARG commit_id +ARG version +ARG sdk_version +ARG time +ARG CGO_ENABLED +ENV BASEPATH /go/src/github.com/Axway/agents-webmethods +ENV APP_USER axway -RUN mkdir -p $APP_HOME -WORKDIR $APP_HOME +RUN mkdir -p ${BASEPATH} +WORKDIR ${BASEPATH} # Copy necessary files COPY . . -RUN export time=`date +%Y%m%d%H%M%S` && \ - export commit_id=${COMMIT_ID} && \ - export version=${VERSION} && \ - export sdk_version=`go list -m github.com/Axway/agent-sdk | awk '{print $2}' | awk -F'-' '{print substr($1, 2)}'` && \ - export GOOS=linux && \ - export CGO_ENABLED=0 && \ - export GOARCH=amd64 && \ +RUN --mount=type=cache,target=/root/.cache/go-build \ go build -tags static_all \ -ldflags="-X 'github.com/Axway/agent-sdk/pkg/cmd.BuildTime=${time}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.BuildVersion=${version}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.BuildCommitSha=${commit_id}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.SDKBuildVersion=${sdk_version}' \ -X 'github.com/Axway/agent-sdk/pkg/cmd.BuildAgentName=webMethodsTraceabilityAgent'" \ - -a -o ${APP_HOME}/bin/webmethods_traceability_agent ${AGENT}/main.go - + -a -o ${BASEPATH}/bin/webmethods_traceability_agent ${BASEPATH}/cmd/traceability/main.go # Create non-root user -RUN addgroup -g 2500 $APP_USER && adduser -u 2500 -D -G $APP_USER $APP_USER -RUN chown -R $APP_USER:$APP_USER ${APP_HOME}/bin/webmethods_traceability_agent - -USER $APP_USER +RUN addgroup -g 2500 ${APP_USER} && adduser -u 2500 -D -G ${APP_USER} ${APP_USER} +RUN chown -R ${APP_USER}:${APP_USER} ${BASEPATH}/bin/webmethods_traceability_agent +USER ${APP_USER} # alpine 3.18 linux/amd64 FROM docker.io/alpine@sha256:d695c3de6fcd8cfe3a6222b0358425d40adfd129a8a47c3416faff1a8aece389 +ENV BASEPATH /go/src/github.com/Axway/agents-webmethods ENV APP_USER axway -ENV APP_HOME /go/src/github.com/Axway/agents-webmethods # Copy binary, user, config file and certs from previous build step COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder $APP_HOME/build/webmethods_traceability_agent.yml /webmethods_traceability_agent.yml -COPY --from=builder ${APP_HOME}/bin/webmethods_traceability_agent /webmethods_traceability_agent +COPY --from=builder ${BASEPATH}/bin/webmethods_traceability_agent /webmethods_traceability_agent +COPY build/webmethods_traceability_agent.yml /webmethods_traceability_agent.yml RUN mkdir /keys /data && \ chown -R axway /keys /data && \ apk --no-cache add openssl libssl3 libcrypto3 musl musl-utils libc6-compat busybox curl && \ find / -perm /6000 -type f -exec chmod a-s {} \; || true - -USER $APP_USER +USER ${APP_USER} VOLUME ["/keys", "/data"] HEALTHCHECK --retries=1 CMD curl --fail http://localhost:${STATUS_PORT:-8989}/status || exit 1 ENTRYPOINT ["/webmethods_traceability_agent"] \ No newline at end of file