Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix APK Adapter Fails to Build on Windows #2658

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions adapter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ ARG GRPC_HEALTH_PROBE_PATH=/bin/grpc_health_probe
ARG TARGETARCH

ARG MOTD="\n\
Welcome to WSO2 Docker Resources \n\
--------------------------------- \n\
This Docker container comprises of a WSO2 product, running with its latest GA release \n\
which is under the Apache License, Version 2.0. \n\
Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n"
Welcome to WSO2 Docker Resources \n\
--------------------------------- \n\
This Docker container comprises of a WSO2 product, running with its latest GA release \n\
which is under the Apache License, Version 2.0. \n\
Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n"

RUN \
addgroup -S -g ${APK_USER_GROUP_ID} ${APK_USER_GROUP} \
Expand All @@ -50,7 +50,7 @@ RUN \
wget -q https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.34/grpc_health_probe-linux-${TARGETARCH} \
&& mv grpc_health_probe-linux-${TARGETARCH} ${GRPC_HEALTH_PROBE_PATH} \
&& if [ "${TARGETARCH}" = "amd64" ]; then echo "${CHECKSUM_AMD64} ${GRPC_HEALTH_PROBE_PATH}" | sha256sum -c -; fi

RUN \
chmod +x ${GRPC_HEALTH_PROBE_PATH} \
&& chown ${APK_USER}:${APK_USER_GROUP} ${GRPC_HEALTH_PROBE_PATH} \
Expand All @@ -61,7 +61,11 @@ WORKDIR ${APK_USER_HOME}
USER ${APK_USER_ID}

COPY resources/conf/config.toml conf/

COPY resources/check_health.sh .
# Remove the Windows line endings (carriage returns)
RUN sed -i 's/\r//' check_health.sh

COPY resources/conf/log_config.toml conf/
COPY ./${TARGETARCH}/main adapter

Expand Down
20 changes: 12 additions & 8 deletions adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The following should be installed in your dev machine.
- [Gradle](https://gradle.org/install/) >= 7.5.1 version
- [Docker](https://docs.docker.com/engine/install/ubuntu/) >= 17.03 version
- [Golang](https://go.dev/doc/install) >= 1.23 version
- [Revive](https://github.com/mgechev/revive#installation) latest version
- [Revive](https://github.com/mgechev/revive#installation) = 1.3.4 version
- [Kubebuilder](https://book.kubebuilder.io/quick-start.html#installation)

## Setting up
Expand Down Expand Up @@ -39,18 +39,22 @@ Code for the operator lies in `{PROJECT_HOME}/adapter/internal/operator`. This w

Following are some tasks with the steps that a developer might do in operator development:

- [Adding a new Kind](#adding-a-new-kind)
- [Adding a new property to an existing Kind](#adding-a-new-property-to-an-existing-kind)
- [Adding validating and defaulting logic](#adding-validating-and-defaulting-logic)
- [WSO2 APK - Adapter](#wso2-apk---adapter)
- [Prerequisites](#prerequisites)
- [Setting up](#setting-up)
- [Operator](#operator)
- [Adding a new Kind](#adding-a-new-kind)
- [Adding a new property to an existing Kind](#adding-a-new-property-to-an-existing-kind)
- [Adding validating and defaulting logic](#adding-validating-and-defaulting-logic)

### Adding a new Kind

1. Decide what the k8s resource group will be depending on whether the CRD is for the control-plane or for the data-plane.

| Plane | k8s group |
| ------------- | ------------- |
| Data Plane | dp |
| Control Plane | cp |
| Plane | k8s group |
| ------------- | --------- |
| Data Plane | dp |
| Control Plane | cp |

2. Decide the version for the CRD. Current version for all the CRDs are used as `v1alpha1`.

Expand Down
8 changes: 7 additions & 1 deletion adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ tasks.register('go_test', Exec) {
environment "APK_test_test_uint32array", "100"
environment "APK_test_test_uint64array", "42949672959"
environment "APK_test_test_uintarray2", "-50"
commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."

def osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
if (osName.contains("windows")) {
commandLine 'cmd', '/c', 'set', 'CGO_ENABLED=1', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."
} else {
commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."
}
}

tasks.named('go_revive_run').configure {
Expand Down
2 changes: 1 addition & 1 deletion adapter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ require (
go.uber.org/zap v1.26.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand All @@ -105,7 +106,6 @@ replace github.com/wso2/apk/common-go-libs => ../common-go-libs
require (
github.com/ghodss/yaml v1.0.0
github.com/stretchr/testify v1.9.0
golang.org/x/sys v0.26.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
sigs.k8s.io/gateway-api v1.2.0
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ import (
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"

"golang.org/x/sys/unix"

"github.com/wso2/apk/adapter/internal/loggers"
"github.com/wso2/apk/adapter/internal/operator/gateway-api/bootstrap"
)
Expand Down Expand Up @@ -76,7 +75,8 @@ func ShutdownManager(readyTimeout time.Duration) error {
signal.Notify(s, os.Interrupt, syscall.SIGTERM)

r := <-s
loggers.LoggerAPKOperator.Info(fmt.Sprintf("received %s", unix.SignalName(r.(syscall.Signal))))
// loggers.LoggerAPKOperator.Info(fmt.Sprintf("received %s", unix.SignalName(r.(syscall.Signal))))
loggers.LoggerAPKOperator.Info(fmt.Sprintf("received %s", strconv.Itoa(int(r.(syscall.Signal)))))

// Shutdown HTTP server without interrupting active connections
if err := srv.Shutdown(context.Background()); err != nil {
Expand Down
16 changes: 10 additions & 6 deletions common-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ ENV COMMON_CONTROLLER_PRIVATE_KEY_PATH=/home/wso2/security/keystore/mg.key
ENV COMMON_CONTROLLER_PUBLIC_CERT_PATH=/home/wso2/security/keystore/mg.pem

ARG MOTD="\n\
Welcome to WSO2 Docker Resources \n\
--------------------------------- \n\
This Docker container comprises of a WSO2 product, running with its latest GA release \n\
which is under the Apache License, Version 2.0. \n\
Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n"
Welcome to WSO2 Docker Resources \n\
--------------------------------- \n\
This Docker container comprises of a WSO2 product, running with its latest GA release \n\
which is under the Apache License, Version 2.0. \n\
Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n"

RUN \
addgroup -S -g ${APK_USER_GROUP_ID} ${APK_USER_GROUP} \
Expand All @@ -53,7 +53,7 @@ RUN \
wget -q https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.34/grpc_health_probe-linux-${TARGETARCH} \
&& mv grpc_health_probe-linux-${TARGETARCH} ${GRPC_HEALTH_PROBE_PATH} \
&& if [ "${TARGETARCH}" = "amd64" ]; then echo "${CHECKSUM_AMD64} ${GRPC_HEALTH_PROBE_PATH}" | sha256sum -c -; fi

RUN \
chmod +x ${GRPC_HEALTH_PROBE_PATH} \
&& chown ${APK_USER}:${APK_USER_GROUP} ${GRPC_HEALTH_PROBE_PATH}
Expand All @@ -64,7 +64,11 @@ USER ${APK_USER_ID}

COPY resources/security security
COPY resources/conf/config.toml conf/

COPY resources/check_health.sh .
# Remove the Windows line endings (carriage returns)
RUN sed -i 's/\r//' check_health.sh

COPY resources/conf/log_config.toml conf/
COPY ./${TARGETARCH}/main common-controller

Expand Down
8 changes: 7 additions & 1 deletion common-controller/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ tasks.register('go_test', Exec) {
environment "APK_test_test_uint32array", "100"
environment "APK_test_test_uint64array", "42949672959"
environment "APK_test_test_uintarray2", "-50"
commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."

def osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
if (osName.contains("windows")) {
commandLine 'cmd', '/c', 'set', 'CGO_ENABLED=1', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."
} else {
commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."
}
}

tasks.named('go_revive_run').configure {
Expand Down
22 changes: 20 additions & 2 deletions common-gradle-scripts/go.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ tasks.register('go_tidy', Exec) {
tasks.register('go_build') {
group 'go'
description 'Compiles the packages named by the import paths, along with their dependencies. AMD64 Archtecture'
dependsOn go_mac_os_build
dependsOn go_linux_build

if(osName.contains("windows")) {
dependsOn go_windows_build
} else {
dependsOn go_mac_os_build
dependsOn go_linux_build
}
}
tasks.register('go_mac_os_build', Exec) {
group 'go'
Expand All @@ -67,3 +72,16 @@ tasks.register('go_linux_build', Exec) {
throw new StopExecutionException('Missing "file" property')
}
}
tasks.register('go_windows_build', Exec) {
group 'go'
description 'Compiles the packages named by the import paths, along with their dependencies. AMD64 Archtecture'
if (project.hasProperty('file')) {
environment 'GOOS', 'linux'
environment 'GOARCH', 'amd64'
environment 'CGO_ENABLED', '0'

commandLine 'go', 'build', '-o', 'amd64/main', file
} else {
throw new StopExecutionException('Missing "file" property')
}
}
Loading