我正在尝试创建一个ARM64 Docker 镜像它能够构建我的 React Native 应用程序的 apk 文件。
背景:
为了练习目的,我使用 5 个 Raspberry Pi 4 板构建了一个 Kubernetes 集群。一切工作正常,Jenkins 正在其上运行,并且后端部分(Java 微服务、Maven)可以在其上构建、部署和运行。
现在我正在尝试创建一个管道安卓应用部分,我建立在反应本机,摇篮。我只是在学习一切如何组合在一起坚持构建 apk关于詹金斯的文件。在本地构建它(在 Linux 上)工作正常,但我无法为其创建 Docker 容器aarch64架构安装了必要的 Android SDK 来使用 Jenkins 构建它。这是我现在所拥有的(告诉我,如果我需要提供更多信息!):
Dockerfile:
FROM openjdk:8-alpine3.9
ENV ANDROID_SDK_ROOT /opt/android-sdk-linux
RUN apk add --no-cache curl wget bash unzip \
&& apk add --no-cache --update nodejs npm \
&& npm install -g react-native-cli
RUN cd /opt \
&& wget -q https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip -O android-commandline-tools.zip \
&& mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools \
&& unzip -q android-commandline-tools.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools \
&& rm android-commandline-tools.zip
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/platform-tools:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin
RUN yes | sdkmanager --licenses
RUN touch /root/.android/repositories.cfg
# This part fails!
# RUN yes | sdkmanager "emulator" "platform-tools"
RUN yes | sdkmanager --update --channel=3
RUN yes | sdkmanager \
"platforms;android-29" \
"build-tools;29.0.3" \
"build-tools;29.0.2" \
"build-tools;29.0.1" \
"build-tools;29.0.0"
詹金斯文件:
pipeline {
agent {
kubernetes {
defaultContainer 'app-build'
yamlFile 'kubernetes-pod.yaml'
}
}
stages {
stage ('print env vars') {
steps {
sh 'printenv'
sh 'echo "JAVA-VERSION: "'
sh 'java -version'
sh 'echo "NODE-VERSION:"'
sh 'node --version'
sh 'echo "NPM version:" '
sh 'npm --version'
sh 'echo "REACT-NATIVE-VERSION:"'
sh 'react-native --version'
}
}
stage ('Gradle Build') {
steps {
sh ('react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res')
dir ('android') {
// this step fails (error message below)
gradlew('assembleRelease', '--scan')
}
}
}
/* ... more steps ... */
}
}
def gradlew(String... args) {
sh "./gradlew ${args.join(' ')} -s"
}
我在 Jenkins 上收到的错误消息如下:
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :react-native-reanimated
Warning: Dependant package with key emulator not found!
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jenkins/agent/workspace/nches_CHEF-8-frontend-deployment/node_modules/react-native-reanimated/android/build.gradle' line: 89
* What went wrong:
A problem occurred configuring project ':react-native-reanimated'.
> Failed to install the following SDK components:
build-tools;29.0.2 Android SDK Build-Tools 29.0.2
Install the missing components using the SDK manager in Android Studio.
kubernetes-pod.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
label: jenkins-agent
job: build-services
namespace: build-services
spec:
containers:
- name: jnlp
image: franzbuholzer/jenkins-jnlp-arm64:4.6
tty: true
- name: maven
image: maven:3.6.3-jdk-11
tty: true
command: ["cat"]
volumeMounts:
- name: repository
mountPath: /root/.m2/repository
- name: docker
image: docker:19.03.13
command: ["cat"]
tty: true
volumeMounts:
- name: docker-sock
mountPath: /var/run/docker.sock
volumes:
- name: repository
persistentVolumeClaim:
claimName: repository
- name: docker-sock
hostPath:
path: /var/run/docker.sock
如果有人能帮助我解决这个问题,我会非常高兴,这样我就可以解决下一个障碍,我想这将是将生成的 apk 复制到另一个 Docker 映像中并将其部署在集群上以使其可下载......