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 APIM APK Agent Fails to Build on Windows #1242

Open
wants to merge 1 commit into
base: master
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ vendor
.vscode/

*.tar.gz
*.tgz
*.rar

# APIM APK Agent builds
apim-apk-agent/arm64/main
apim-apk-agent/amd64/main

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

Expand Down
16 changes: 10 additions & 6 deletions apim-apk-agent/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.25/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 apim-apk-agent
Expand Down
8 changes: 7 additions & 1 deletion apim-apk-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ allprojects {
tasks.register('go_test', Exec) {
group 'go'
description 'Automates testing the packages named by the import paths.'
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 ./..."
}
environment "APK_HOME", "$rootDir"
}

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')
}
}