我有一個在 Jenkins 中運行的 docker build 命令執行 shell
docker build -f ./fastlane.dockerfile \
-t fastlane-test \
--build-arg PLAY_STORE_CREDENTIALS=$(cat PLAY_STORE_CREDENTIALS) \
.
PLAY_STORE_CREDENTIALS是使用托管檔案保存在 Jenkins 中的 JSON 檔案。然后,在我的Dockerfile中,我有
ARG PLAY_STORE_CREDENTIALS
ENV PLAY_STORE_CREDENTIALS=$PLAY_STORE_CREDENTIALS
WORKDIR /app/packages/web/android/fastlane/PlayStoreCredentials
RUN touch play-store-credentials.json
RUN echo $PLAY_STORE_CREDENTIALS >> ./play-store-credentials.json
RUN cat play-store-credentials.json
cat注銷一個空行或什么都沒有。
內容PLAY_STORE_CREDENTIALS:
{
"type": "...",
"project_id": "...",
"private_key_id": "...",
"private_key": "...",
"client_email": "...",
"client_id": "...",
"auth_uri": "...",
"token_uri": "...",
"auth_provider_x509_cert_url": "...",
"client_x509_cert_url": "..."
}
知道問題出在哪里嗎?
uj5u.com熱心網友回復:
實際上有一個名為 的檔案PLAY_STORE_CREDENTIALS嗎?如果是,并且如果它是標準 JSON 檔案,我希望您給定的命令列會失敗;如果檔案包含任何空格(這對于 JSON 檔案來說是典型的),那么該命令應該會導致錯誤,例如...
"docker build" requires exactly 1 argument.
例如,如果我有PLAY_STORE_CREDENTIALS您問題的示例內容,我們會看到:
$ docker build -t fastlane-test --build-arg PLAY_STORE_CREDENTIALS=$(cat PLAY_STORE_CREDENTIALS) .
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
...因為您沒有正確參考您的論點。如果您采用@β.εηοιτ.βε 的建議并參考該cat命令,它似乎按預期構建:
$ docker build -t fastlane-test --build-arg PLAY_STORE_CREDENTIALS="$(cat PLAY_STORE_CREDENTIALS)" .
[...]
Step 7/7 : RUN cat play-store-credentials.json
---> Running in 29f95ee4da19
{ "type": "...", "project_id": "...", "private_key_id": "...", "private_key": "...", "client_email": "...", "client_id": "...", "auth_uri": "...", "token_uri": "...", "auth_provider_x509_cert_url": "...", "client_x509_cert_url": "..." }
Removing intermediate container 29f95ee4da19
---> b0fb95a9d894
Successfully built b0fb95a9d894
Successfully tagged fastlane-test:latest
您會注意到生成的檔案不保留行尾;那是因為您沒有$PLAY_STORE_CREDENTIALS在echo陳述句中參考變數。你應該這樣寫:
RUN echo "$PLAY_STORE_CREDENTIALS" >> ./play-store-credentials.json
最后,不清楚為什么要使用環境變數傳輸這些資料,而不僅僅是使用COPY命令:
COPY PLAY_STORE_CREDENTIALS ./play-store-credentials.json
在上面的示例中,我正在使用以下 Dockerfile 進行測驗:
FROM docker.io/alpine:latest
ARG PLAY_STORE_CREDENTIALS
ENV PLAY_STORE_CREDENTIALS=$PLAY_STORE_CREDENTIALS
WORKDIR /app/packages/web/android/fastlane/PlayStoreCredentials
RUN touch play-store-credentials.json
RUN echo $PLAY_STORE_CREDENTIALS >> ./play-store-credentials.json
RUN cat play-store-credentials.json
更新
這是一個使用該COPY命令的示例,其中PLAY_STORE_CREDENTIALSbuild 引數的值是一個檔案名:
FROM docker.io/alpine:latest
ARG PLAY_STORE_CREDENTIALS
WORKDIR /app/packages/web/android/fastlane/PlayStoreCredentials
COPY ${PLAY_STORE_CREDENTIALS} play-store-credentials.json
RUN cat play-store-credentials.json
如果我在名為 的檔案中有憑據creds.json,則會像這樣成功構建:
docker build -t fastlane-test --build-arg PLAY_STORE_CREDENTIALS=creds.json .
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/476103.html
