使用 docker 和 bitbucket 管道的 android 环境 [英] android environment using docker and bitbucket pipelines

查看:45
本文介绍了使用 docker 和 bitbucket 管道的 android 环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Bitbucket 管道(测试版)和 docker 非常陌生.之前没有 CI 集成方面的经验

我关注了

第 4 步.使用成功构建项目

$ eval "$(docker-machine env default)"$ docker build -t uber/android-build-environment .

第 5 步.直接将工作改为android项目

第 6 步.运行此命令时,此步骤出现问题

docker run -i -v $PWD:/project -t uber/android-build-environment/bin/bash/project/ci/build.sh

错误来了:

/bin/bash:/project/ci/build.sh: 没有这样的文件或目录

Docker 机器详细信息

docker-machine ls名称活动驱动程序状态 URL 群 Docker 错误默认 - virtualbox 运行 tcp://192.168.99.100:2376 v1.12.1

Docker 服务

docker 服务 ls

Docker Machine ENV

导出 DOCKER_TLS_VERIFY="1"出口 DOCKER_HOST="tcp://192.168.XX.XXX:XXXX"导出 DOCKER_CERT_PATH="/Users/gaurav/.docker/machine/machines/default"导出 DOCKER_MACHINE_NAME="默认"# 运行这个命令来配置你的shell:# eval $(docker-machine 环境)

解决方案

如果我正确理解您的问题:从技术上讲,您甚至不需要安装 Docker 在你的本地机器上,以便在你的 Bitbucket 管道中使用它(尽管它对调试很有帮助).

Bitbucket Pipelines 可以配置为使用来自 Docker Hub 的 Docker,以及您提到的那个(uber/android-build-environment) 对我来说效果很好.

只需将 bitbucket-pipelines.yml 添加到项目的根目录,例如:

image: uber/android-build-environment:latest管道:默认:- 步:脚本:- 构建.sh

我喜欢在它自己的 ash 脚本文件 (build.sh) 中组织我的构建过程,但那是 可选 (您可以在 <script 指令下的 href="http://yaml.org/" rel="noreferrer">yaml 文件).bitbucket-pipelines.yml 文件的示例(以及更多详细信息)可以在 Bitbucket Pipelines 的语言指南 页面.

我的 build.sh 脚本(也在项目的根目录中,但可以放在子目录中,只要您在 bitbucket-pipelines.yml 中这样引用它,例如 scripts/build.sh):

#!/bin/shmkdir "${ANDROID_HOME}/licenses" ||真的回声8933bad161af4178b1185d1a37fbf41ea5269c55">${ANDROID_HOME}/licenses/android-sdk-license"./gradlew assembleDebug

许可证部分允许 Android Gradle 进程自动为您下载 Android 依赖项,如本答案中所述.

为了更好地衡量,相应地设置构建脚本的权限:

git update-index --chmod=+x build.sh

确保您已启用 Bitbucket Pipelines(从您的回购页面:Settings -> Pipelines: Settings -> Enable Pipelines).

然后只需提交 bitbucket-pipelines.ymlbuild.sh 并推送到您的 BitBucket 存储库.为您的项目构建的 Bitbucket Pipelines 应该在您推送后不久开始.Bitbucket Pipelines 将从 Docker Hub 下载 uber/android-build-environment Docker 并检查您的项目并在 Docker 中运行 build.sh 脚本.

<小时>

如果您的 Bitbucket Pipelines 构建失败并且您希望在本地计算机上运行相同的环境,那么您所描述的在本地计算机上设置 Docker 的过程会非常有用,这样您就可以对其进行试验并测试对build.sh 脚本在实际提交并推送到您的仓库之前.

如果您(在本地)运行,也可能会有所帮助:

docker run -it uber/android-build-environment

它将启动 Docker(在您的本地计算机上)并将您置于交互式 shell 中,以便您可以浏览并更好地了解 Docker 环境.

另请注意,Bitbucket Pipelines 在 Docker 中克隆您的存储库,作为构建过程的一部分(据我所知),您没有在本地机器上运行的 Docker 上完成,这可能导致了一些您对您的 build.sh 脚本不存在感到困惑.

如果您希望本地机器上的目录存在于 Docker 中(您正在本地机器上运行,也许是为了测试在您想要使用的 Docker 中的本地机器上构建项目),您可以使用以下命令将当前工作目录挂载到本地运行的 Docker 中的 /project 的命令:

docker run -v `pwd`:/project -it uber/android-build-environment

更多细节可以在 挂载主机目录作为数据卷.

正如@ming-c 在他们的 answer 中指出的,Docker Hub;当然值得四处浏览,看看是否能找到最适合您需求的图片.

I am very new to Bitbucket pipelines (Beta) and docker.No previous experience on CI integration

I followed this question , But no clear description for beginners

I am trying to set up Continuous Integration (CI) in Bitbucket Pipelines for Android Project using docker container

I want to use my previous android project with this container

Steps I followed

Step 1. Installed Docker Software tools . Successfully installed.

Step 2. Created Virtual Machine Successfully

Step 3 . Created container from Kitematic (Beta) Uber/Android-Build-Environment

Step 4. Build Project Successfully using

$ eval "$(docker-machine env default)"

$ docker build -t uber/android-build-environment .

Step 5. Change working directly to android project

Step 6. Problem is in this step while running this command

docker run -i -v $PWD:/project -t uber/android-build-environment /bin/bash /project/ci/build.sh

Error come :

/bin/bash: /project/ci/build.sh: No such file or directory

Docker-machine details

docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.1

Docker Service

docker service ls

Docker Machine ENV

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.XX.XXX:XXXX"
export DOCKER_CERT_PATH="/Users/gaurav/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $(docker-machine env)

解决方案

If I understand your question correctly: you technically don't even need to install Docker on your local machine in order to use it in your Bitbucket Pipelines (although it can be quite helpful for debugging).

Bitbucket Pipelines can be configured to use a Docker from Docker Hub, and the one you mentioned (uber/android-build-environment) worked well for me.

Simply add a bitbucket-pipelines.yml to the root of your project, for example:

image: uber/android-build-environment:latest

pipelines:
  default:
    - step:
        script:
          - build.sh

I like to organize my build process in it's own ash script file (build.sh) but that is optional (you could instead put multiple bulleted commands in the yaml file under the script directive). Examples of (and more details about) the bitbucket-pipelines.yml file can be found on the Language guides for Bitbucket Pipelines page.

My build.sh script (also in the root of the project, but could be placed in a subdirectory as long as you refer to it as such in your bitbucket-pipelines.yml, e.g. scripts/build.sh):

#!/bin/sh

mkdir "${ANDROID_HOME}/licenses" || true
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "${ANDROID_HOME}/licenses/android-sdk-license"

./gradlew assembleDebug

The licenses portion allows the Android Gradle process to automatically download Android dependencies for you, as mentioned in this answer.

For good measure, set the permissions on the build script accordingly:

git update-index --chmod=+x build.sh

Make sure that you've enabled Bitbucket Pipelines (from your repo page: Settings -> Pipelines: Settings -> Enable Pipelines).

Then just commit the bitbucket-pipelines.yml and build.sh and push to your BitBucket repo. The Bitbucket Pipelines build for your project should begin shortly after your push. The Bitbucket Pipelines will download the uber/android-build-environment Docker from Docker Hub and checkout your project and run the build.sh script within the Docker.


The process you were describing of setting up the Docker on your local machine can be really helpful if your Bitbucket Pipelines build fails and you want to have the same environment running on your local machine so you can experiment with it and test changes to the build.sh script before actually committing and pushing to your repo.

Might also prove helpful if you ran (locally):

docker run -it uber/android-build-environment

Which will start up the Docker (on your local machine) and put you in an interactive shell, so that you can browse around and gain a better understanding of the Docker environment.

Also note that the Bitbucket Pipelines clones your repo in the Docker as part of the build process (which as far as I could tell) you had not done on the Docker running on your local machine, which may have led to some of your confusion about your build.sh script not being present.

If you want a directory on your local machine to exist within a Docker (that you are running on your local machine, perhaps to test building a project on your local machine within a Docker you want to use) you can use the following command to mount your current working directory to /project within the locally running Docker:

docker run -v `pwd`:/project -it uber/android-build-environment

More details can be found at Mount a host directory as a data volume.

As @ming-c pointed out in their answer, there are many other Docker images available on Docker Hub; it is certainly worth browsing around to see if you can find an image best suited to your needs.

这篇关于使用 docker 和 bitbucket 管道的 android 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆