Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

continuous integration - android environment using docker and bitbucket pipelines

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

Successfully Docker full

Step 4. Build Project Successfully using

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

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

enter image description here

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

Error Image

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...