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

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

问题描述

我对于Bitbucket管道(beta)和docker没有新意。



我遵循



步骤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-machine详情

  docker-machine ls 
名称ACTIVE DRIVE状态URL SWARM DOCKER错误
默认值 - virtualbox运行tcp://192.168 .99.100:2376 v1.12.1

Docker服务 b
$ b

  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
#运行此命令配置您的shell:
#eval $(docker-machine env)


方案

如果我正确理解您的问题:您在技术上甚至不需要安装 Docker <



Bitbucket Pipelines可以配置为使用Docker来管理你的Bitbucket管道从 Docker Hub 和您提到的( uber / android-build-environment )对我来说效果不错。



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

  image:uber / android-build-environment:latest 

管道:
默认值:
- 步骤:
脚本:
- build.sh



我喜欢将自己的构建过程组织成自己的脚本文件c $ c> build.sh ),但这是可选(您可以将多个项目符号命令放在 yaml 文件在脚本指令下)。 bitbucket-pipelines.yml 文件的示例(以及更多详细信息)可以在 Bitbucket管道语言指南页面。



我的 build.sh 脚本(也在项目的根目录中,但是可以放在一个子目录中,只要在 bitbucket- pipelines.yml ,例如 scripts / build.sh ):

 #!/ bin / sh 

mkdir$ {ANDROID_HOME} / licenses|| true
echo8933bad161af4178b1185d1a37fbf41ea5269c55> $ {ANDROID_HOME} / licenses / android-sdk-license

./gradlew assembleDebug

许可证部分允许Android Gradle过程为您自动下载Android依赖关系,如本 answer 中所述。 。



为了良好的衡量,对构建脚本设置权限因此:

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

确保您已经从您的仓库页面启用了Bitbucket管道: Settings - > 管道:设置 - > 启用管道)。



然后只需提交 bitbucket-pipelines.yml build.sh 并推送到您的BitBucket仓库。 Bitbucket管道构建为您的项目应该开始不久后你的推。 Bitbucket Pipelines将从Docker Hub下载 uber / android-build-environment Docker并检出您的项目并运行 build.sh 脚本。






您在本地机器上设置Docker的过程可以是真的很有帮助,如果你的Bitbucket管道构建失败,你想在本地机器上运行相同的环境,所以你可以尝试它,并测试对 build.sh 脚本的更改



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

  docker run -it uber / android-build-environment 

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



注意,Bitbucket管道克隆你的仓库在Docker作为构建过程的一部分(据我所知),你没有做在本地机器上运行的Docker,这可能导致一些你的混乱关于你的 build.sh 脚本不存在。



如果您希望本地计算机上的目录存在于Docker (你在你的本地机器上运行,或许在你想使用的Docker中在你的本地机器上测试一个项目),你可以使用下面的命令将当前工作目录挂载到 / project 在本地运行的Docker中:

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

更多细节可以在将主机目录作为数据卷挂载。 / p>

As @ ming-c在他们的回答中指出,是 Docker Hub 上提供的许多其他Docker图片;它是值得浏览,看看你能找到一个最适合你的需要的图片。


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.

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

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