From 88ab39a232927623c2082102874ecd1edb690209 Mon Sep 17 00:00:00 2001 From: phlummox Date: Thu, 13 Jan 2022 12:24:09 +0000 Subject: [PATCH] update dockerfile and ci scripts --- .github/workflows/build.yml | 165 ++++++++++++++++++++++++++++++++++++ .gitpod.yml | 27 ------ .travis.yml | 26 ------ .travis/docker_build | 15 ---- .travis/docker_push | 22 ----- Dockerfile | 158 +++++++++++++++++++++++++--------- HACKING.md | 11 +++ LICENSE.txt | 27 ++++++ Makefile | 58 ++++++++++++- README.md | 19 +---- build.py | 89 +++++++++++++++++++ 11 files changed, 467 insertions(+), 150 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .gitpod.yml delete mode 100644 .travis.yml delete mode 100755 .travis/docker_build delete mode 100755 .travis/docker_push create mode 100644 HACKING.md create mode 100644 LICENSE.txt create mode 100755 build.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9548c74 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,165 @@ + +name: build-push + +on: + push: + paths-ignore: + - '**.md' + - '.gitignore' + - '.dockerignore' + pull_request: + paths-ignore: + - '**.md' + - '.gitignore' + - '.dockerignore' + release: + types: + - created + +env: + REGISTRY: ghcr.io + DOCKER_HUB_OWNER: phlummox + +jobs: + docker_build: + name: docker build + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + name: Check out code + + - name: set docker image info + id: info + shell: bash + run: | + set -x + IMAGE_NAME=$(make print-image-name) + IMAGE_VERSION=$(make print-image-version) + echo "::set-output name=IMAGE_NAME::${IMAGE_NAME}" + echo "::set-output name=IMAGE_VERSION::${IMAGE_VERSION}" + + - name: check info ok + run: | + IMAGE_NAME="${{ steps.info.outputs.IMAGE_NAME }}" + printf 'IMAGE_NAME is: <<%s>>\n' "${IMAGE_NAME}" + if [ -z ${IMAGE_NAME} ]; then + false + fi + + IMAGE_VERSION="${{ steps.info.outputs.IMAGE_VERSION }}" + printf 'IMAGE_VERSION is: <<%s>>\n' "${IMAGE_VERSION}" + if [ -z ${IMAGE_VERSION} ]; then + false + fi + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + + - name: Log in to github Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # not sure this is actually needed + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: print stuff + shell: bash + run: | + printf 'tags are: <<%s>>\n' "${{ steps.meta.outputs.tags }}" + printf 'tags labels are: <<%s>>\n' "${{ steps.meta.outputs.labels }}" + printf 'repos is: <<%s>>\n' "${{ github.repository }}" + + # really, this is just using info that _mostly_ + # could've been got from makefile. + # But some is from CI environment. + - name: Build Docker image + shell: bash + run: | + set -x + + export IMAGE_NAME="${{ steps.info.outputs.IMAGE_NAME }}" + export GH_IMAGE_ID="${{ env.REGISTRY }}/${{ github.repository }}/${{ steps.info.outputs.IMAGE_NAME }}" + export IMAGE_VERSION="${{ steps.info.outputs.IMAGE_VERSION }}" + export REPO_OWNER="${{ github.repository_owner }}" + + echo "${{ steps.meta.outputs.labels }}" > oc_labels + # " + + python3 ./build.py + + - name: push to github registry + if: github.event_name != 'pull_request' + shell: bash + run: | + set -x + set -euo pipefail + + GH_IMAGE_ID=${{ env.REGISTRY }}/${{ github.repository }}/${{ steps.info.outputs.IMAGE_NAME }} + IMAGE_VERSION=${{ steps.info.outputs.IMAGE_VERSION }} + + #docker push ${GH_IMAGE_ID}:${IMAGE_VERSION}-builder + docker push ${GH_IMAGE_ID}:${IMAGE_VERSION} + docker tag ${GH_IMAGE_ID}:${IMAGE_VERSION} ${GH_IMAGE_ID}:latest + docker push ${GH_IMAGE_ID}:latest + + # whenever the tag looks like a version, we push + # to Docker Hub. It's up to the maintainer to ensure that + # the right version is being pushed (i.e. that what version + # the makefile spits out is the version for the current tag) + - name: push to docker registry + if: startsWith(github.ref, 'refs/tags/v') + shell: bash + run: | + set -x + set -euo pipefail + + GH_IMAGE_ID="${{ env.REGISTRY }}/${{ github.repository }}/${{ steps.info.outputs.IMAGE_NAME }}" + DOCKER_IMAGE_ID="docker.io/${{ env.DOCKER_HUB_OWNER }}/${{ steps.info.outputs.IMAGE_NAME }}" + IMAGE_VERSION=${{ steps.info.outputs.IMAGE_VERSION }} + + docker tag ${GH_IMAGE_ID}:${IMAGE_VERSION} ${DOCKER_IMAGE_ID}:${IMAGE_VERSION} + docker push ${DOCKER_IMAGE_ID}:${IMAGE_VERSION} + docker tag ${GH_IMAGE_ID}:latest ${DOCKER_IMAGE_ID}:latest + docker push ${DOCKER_IMAGE_ID}:latest + # " + + - name: create release + if: startsWith(github.ref, 'refs/tags/v') + run: | + set -x + + ref_name='${{github.ref_name}}' + version="${ref_name:1}" # strip leading 'v' + + # download github-release tool + github_rel_url="https://github.com/github-release/github-release/releases/download/v0.10.0/linux-amd64-github-release.bz2" + curl -L "${github_rel_url}" | bunzip2 > github-release + chmod a+rx ./github-release + + export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + IFS='/' read repo_user repo_name <<<$(echo "${{github.repository}}") + + ./github-release release \ + --user $repo_user \ + --repo $repo_name \ + --tag ${{github.ref_name}} \ + --name "Version $version" \ + --description "See the changelog for a detailed list of changes" \ + --draft + diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index 72e4c48..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,27 +0,0 @@ -github: - prebuilds: - # # enable for the master/default branch (defaults to true) - # master: true - # # enable for all branches in this repo (defaults to false) - # branches: true - # # enable for pull requests coming from this repo (defaults to true) - # pullRequests: true - # enable for pull requests coming from forks (defaults to false) - pullRequestsFromForks: true - # add a "Review in Gitpod" button as a comment to pull requests (defaults to true) - addComment: true - # add a "Review in Gitpod" button to pull requests (defaults to false) - addBadge: true - # add a label once the prebuild is ready to pull requests (defaults to false) - addLabel: prebuilt-in-gitpod - -checkoutLocation: work -workspaceLocation: / -image: - file: Dockerfile -ports: - - port: 6080 - protocol: "http" -tasks: -# - command: "go get -v ./... && go run main.go" - - command: "echo hi" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f853316..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: ruby - -services: - - docker - -# docker hub login -env: - global: - - secure: g18iMKLG5ryZmk/FVsTk2NHEPVI/PV8QyRTQhu/UNmNZs/5b1R6pTiKqgcDP+eCjIh7aDNfvHmJD6p4dOYOaMWdZuWS/gNY9f8Xf74MIjW1yvi/NXL0v11qvjXpYI3bnMB3tzG96S2u61Gtd3EOt2vleiziyZxjvGa12PbOxxvujdlcmXhoP43y2LdYdZvJl6Io45YlDkBKjPlmtfpMP0MCrizuBGOslHWJHp4RgVzjmLQVv2Op2yDYH5wl8IbQNcdcwTKahO6faj9JGHLMfqkM2pvSJPlLGqAwOVyWp/NMryn1COpKxkYKvv+NxPXPFoe3S/IvKi7AoAIq6elT8YR/3zaIxYQG3YMREn4pp5s0DP5+AlXv3+/WT/hoyEUtf10AIl/4A8tNNRRDgDiufzAknGcx0BYV+z6AaF5mEdo8l6ug5JKyEMyaj3FAE4O/Ij5EqqJLt+ahdtQhR9KErnPsGLVFuBtTU9H+29bsZ5eF8ySZTnowRY5ALPLoLcXYPAXhVz2h5nxEkmeoHZnnOqUUOH8O+xSik40RQnXNbJZvzEyiKPJ7ztsaS+BSC18Tz+KYRbcriXS9PglxMzba6oNNHxMqVs9XEloUJGMTPkmZbpPZhaBIGUb/uvr2ludGp1h6+pYdvYHgux7/Pk27p+H9RsgfZLd8LY/1Z1BuDLg8= - - secure: hnqD6XTWlGumIPuY8Y4Iv0rypjrm40hPUEgg7hsjKy7ReYrIVBVpyn2M1rx2M+9OEidqzZfGx7dWuFDkqWC08sVggkC2fxyfPPca4d8+a9Zhn9zgRpDdqLLLcrBZhcjmpQ2VOznhSKCsOvpBdjwlX+rw0itCoHtee5/99Puo95SDXPWHzNACpionZCSJE+dIaP5Y8Y/YFL7juGRlblSdC2Y2DdHB+++7gOh987ky0z51dPTX3fryWra2sDmXW1vDnMvoj98sM0UptY0o2+kuZL9rxNrIxX/ipBxbqUtxhJaQmny9diEifPZEEr6DLGtiau0R/+nzH+L0006smFHExiE5OKGFxJ8xqrbZJgK9mpBOTARu2AvxfUzuyPx0WOQaMs9Xa6fxCdgFL9NAwu+YtRI4bRWdh8TqWZZeTDFksSLtIO5F02NAoxtm/hPJR87mtJjlpM9B5+kWzYd58owQBEbRAU/h/FxJ/uoeCHv+4+K9jELihOb4LtQPv027wBjDRQtGn2mdS9+HxPFD5DVtEW6GB4qjM68Q+tUE3ibVBsnJylkmhYPKWaDpJ5wxnIXT96lg5HPS5isPXBSjUrir/qExQ2bK1p9jF3fqBXsi1FoMx/ZAeTIf8Kn2l7Kx759wEPbqlPhHoUy0GBXnyFMaXhGnxrCM+BDG23DyeRO+HMU= - - -script: - - | - set -ex - bash .travis/docker_build - set +ex - -deploy: - provider: script - skip_cleanup: true - script: bash .travis/docker_push - on: - branch: master - tags: true - diff --git a/.travis/docker_build b/.travis/docker_build deleted file mode 100755 index bfef927..0000000 --- a/.travis/docker_build +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -# find most recent tag -VERSION="$(git describe --abbrev=0)" - -# drop first char -rest=${VERSION#?}; - -docker build -t "phlummox/android-studio:${rest}" . -docker build -t "phlummox/android-studio:latest" . - -set +ex - diff --git a/.travis/docker_push b/.travis/docker_push deleted file mode 100755 index 74ab7f6..0000000 --- a/.travis/docker_push +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -# find most recent tag -VERSION="$(git describe --abbrev=0)" - -# only when first char in tag is "v" - -first_lett="${VERSION%"${VERSION#?}"}" - -if [[ ! "$first_lett"=="v" ]]; then - exit 0 -fi - -rest=${VERSION#?}; - -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -docker push "phlummox/android-studio:${rest}" -docker push "phlummox/android-studio:latest" - -set +ex diff --git a/Dockerfile b/Dockerfile index 8bfbaa2..54cda8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,60 +1,140 @@ -FROM gitpod/workspace-full-vnc@sha256:331a933c3bce7d7cb3e78f8cfac93ae706091575758adeba3a86072d585e52b0 +FROM gitpod/workspace-full-vnc:latest +SHELL ["/bin/bash", "-c"] -ARG ANDROID_STUDIO_URL=https://dl.google.com/dl/android/studio/ide-zips/4.0.0.16/android-studio-ide-193.6514223-linux.tar.gz -ARG ANDROID_STUDIO_VERSION=4.0 +ARG USER_NAME=gitpod +# Install dart USER root +# Install dart and other ubuntu packages +# Required packages for android studio: +# - https://developer.android.com/studio/install#64bit-libs +# requires: libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 +# For flutter: +# - https://docs.flutter.dev/get-started/install/linux +# (requires libglu1-mesa for `flutter test`) +# - desktop prereqs: +# https://docs.flutter.dev/desktop#additional-linux-requirements +# (clang, cmake, gtk dev headers, ninja, pkg-config) +USER root +RUN dpkg --add-architecture i386 \ + && apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg \ + && curl -fsSL https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ + && curl -fsSL https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list | \ + tee /etc/apt/sources.list.d/dart_stable.list \ + && apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ + clang \ + cmake \ + dart \ + file \ + git \ + lib32z1 \ + libbz2-1.0:i386 \ + libc6:i386 \ + libglu1-mesa \ + libgtk-3-dev \ + libncurses5:i386 \ + libstdc++6:i386 \ + ninja-build \ + openjdk-11-jdk \ + pkg-config \ + pv \ + sudo \ + unzip \ + wget \ + xz-utils \ + zip \ + && \ + apt-get clean && \ + rm -rf /var/cache/apt/* && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf /tmp/* && \ + rm -rf /var/tmp/* && \ + update-java-alternatives --set java-1.11.0-openjdk-amd64 && \ + rm -rf /home/${USER_NAME}/.{rustup,pyenv,nvm} && \ + rm -rf /home/${USER_NAME}/{go,go-packages,linuxbrew} && \ + apt-get purge -y emacs-common + +USER ${USER_NAME} + +# Install flutter +# For Flutter SDK releases, +# see https://docs.flutter.dev/development/tools/sdk/releases -# Install dependencies -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y \ - coreutils \ - curl \ - expect \ - lib32gcc1 \ - lib32ncurses5-dev \ - lib32stdc++6 \ - lib32z1 \ - libc6-i386 \ - pv \ - unzip \ - wget && \ - apt-get clean && \ - rm -rf /var/cache/apt/* && \ - rm -rf /var/lib/apt/lists/* && \ - rm -rf /tmp/* && \ - rm -rf /var/tmp/* +ARG FLUTTER_VERSION=2.8.1-stable +ARG FLUTTER_URL=https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}.tar.xz RUN \ - wget -O /opt/android-studio-ide.tar.gz $ANDROID_STUDIO_URL && \ - export sha="$(sha256sum /opt/android-studio-ide.tar.gz)" ; \ - if [ "$sha" != "70c04dc542281c015a700fad73d7d62ce9dace774bc12050cad9f1d6363112eb /opt/android-studio-ide.tar.gz" ]; then \ - echo "SHA-256 Checksum mismatch, aborting installation"; \ - rm -f /opt/android-studio-ide.tar.gz; exit 1; \ - else \ - cd /opt && tar xf android-studio-ide.tar.gz && rm android-studio-ide.tar.gz; \ - fi + curl -s ${FLUTTER_URL} | tar xf - --xz -C $HOME + +## android command-line tools: from +## https://developer.android.com/studio/index.html#command-tools +## Handy to have them in addition to studio (as the studio-supplied ones +## seem not to work great with e.g. openjdk 11). + +ARG ANDROID_TOOLS_ZIP=commandlinetools-linux-7583922_latest.zip +ARG ANDROID_TOOLS_URL=https://dl.google.com/android/repository/${ANDROID_TOOLS_ZIP} +ARG ANDROID_TOOLS_CHECKSUM=124f2d5115eee365df6cf3228ffbca6fc3911d16f8025bebd5b1c6e2fcfa7faf + +# see https://developer.android.com/studio/command-line/variables +ENV ANDROID_HOME=/home/${USER_NAME}/Android/Sdk \ + ANDROID_SDK_ROOT=/home/${USER_NAME}/Android/Sdk + +RUN \ + cd $HOME && \ + wget -q $ANDROID_TOOLS_URL \ + && printf '%s commandlinetools-linux-7583922_latest.zip' "$ANDROID_TOOLS_CHECKSUM" | sha256sum -c - \ + && mkdir -p $ANDROID_SDK_ROOT/cmdline-tools \ + && unzip -q commandlinetools-linux-*.zip -d /tmp \ + && rm -f commandlinetools-linux-*.zip \ + && mv /tmp/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest + +RUN \ + yes | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "platform-tools" "build-tools;31.0.0" "platforms;android-31" + +ENV ANDROID_STUDIO_LOC=/opt/android-studio +ENV PATH=/home/${USER_NAME}/flutter/bin:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$PATH:$ANDROID_STUDIO_LOC/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH +RUN echo "export ANDROID_HOME=$ANDROID_HOME" >> /home/${USER_NAME}/.bashrc \ + && echo "export ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >> /home/${USER_NAME}/.bashrc \ + && echo 'export PATH=/home/${USER_NAME}/flutter/bin:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$PATH:$ANDROID_STUDIO_LOC/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH' >> /home/${USER_NAME}/.bashrc + +# Install studio +ARG ANDROID_STUDIO_URL=https://dl.google.com/dl/android/studio/ide-zips/2020.3.1.26/android-studio-2020.3.1.26-linux.tar.gz +RUN curl -s $ANDROID_STUDIO_URL | sudo tar xf - --gzip -C /opt + +RUN \ + flutter config --android-studio-dir=$ANDROID_STUDIO_LOC \ + && yes | flutter doctor --android-licenses \ + && flutter doctor -v + +RUN flutter/bin/flutter precache + +USER root # fix display resolution RUN \ sed -i 's/1920x1080/1280x720/' /usr/bin/start-vnc-session.sh -USER gitpod +USER ${USER_NAME} RUN \ mkdir -p $HOME/.local/bin && \ printf '\nPATH=$HOME/.local/bin:$PATH\n' | \ - tee -a /home/gitpod/.bashrc && \ + tee -a /home/${USER_NAME}/.bashrc && \ ln -s /opt/android-studio/bin/studio.sh \ - /home/gitpod/.local/bin/android_studio && \ + /home/${USER_NAME}/.local/bin/android_studio && \ : "if running locally (vs using gitpod in cloud) need to create /workspace " && \ sudo mkdir -p /workspace/.gradle && \ - sudo chown -R gitpod:gitpod /workspace + sudo chown -R ${USER_NAME}:${USER_NAME} /workspace -ARG ANDROID_INSTALLATION_URL=https://github.com/phlummox/android-studio-docker/releases/download/v0.1/android-studio-installation.tar.xz -RUN \ - cd $HOME && \ - wget -O - $ANDROID_INSTALLATION_URL | tar x --xz +## For Qt WebEngine on docker +ENV QTWEBENGINE_DISABLE_SANDBOX 1 + diff --git a/HACKING.md b/HACKING.md new file mode 100644 index 0000000..1e3abbe --- /dev/null +++ b/HACKING.md @@ -0,0 +1,11 @@ + +flow of info is: + +- Makefile is preferred source of truth + for names, versions, etc. +- Then current env vars +- build.py uses these to generate command-line invocations + of docker +- preferred way to build is to invoke build.py, not use makefile + targets + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..9363cb8 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +BSD 2-Clause License + +Copyright (c) 2021, phlummox +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile index 6d6d99c..e0ec2ee 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,58 @@ -# makefile for doing a trial build of the dockerfile +.PHONY: docker-build docker-shell print-build-args \ + default build \ + print-docker-hub-image -IMG=phlummox/gitpod-android-studio:0.1 +SHELL=bash + +default: + echo pass + +###### +# docker stuff + +REPO=phlummox + +IMAGE_NAME=gitpod-android-studio + +IMAGE_VERSION=0.1.3 + +print-image-name: + @echo $(IMAGE_NAME) + +print-image-version: + @echo $(IMAGE_VERSION) + +GIT_REF=$(shell git rev-parse HEAD) +GIT_COMMIT_DATE=$(shell git show -s --format=%cI $(GIT_REF)) +GIT_TAGS=$(shell git tag -l) + +print-build-args: + @printf '%s %s\n' '--build-arg GIT_REF=$(GIT_REF)' \ + '--build-arg GIT_COMMIT_DATE=$(GIT_COMMIT_DATE)' \ + '--build-arg VERSION=$(IMAGE_VERSION)' + +print-docker-hub-image: + @printf '%s' "$(REPO)/$(IMAGE_NAME)" + +docker-build: + docker build \ + -f Dockerfile $(TAGS_TO_ADD) $(TAGS_IN) \ + -t $(REPO)/$(IMAGE_NAME):$(IMAGE_VERSION) . + +DEVICES = --device /dev/kvm:/dev/kvm \ + --device /dev/dri:/dev/dri \ + -v /tmp/.X11-unix:/tmp/.X11-unix + + +docker-shell: + -docker rm android-studio-ctr + docker -D run -e DISPLAY -it --net=host \ + --name 'android-studio-ctr' \ + $(DOCKER_LIMITS) \ + -v $$HOME/dev/:/home/dev \ + -v $$PWD:/work --workdir=/work \ + $(MOUNT) $(DEVICES) --env QT_X11_NO_MITSHM=1 \ + $(REPO)/$(IMAGE_NAME):$(IMAGE_VERSION) bash -build: - docker build -t $(IMG) . diff --git a/README.md b/README.md index 5e675a7..0c259c2 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,13 @@ ## android-studio-docker [WORK IN PROGRESS] -[![Docker hub version](https://img.shields.io/docker/v/phlummox/android-studio?label=Docker%20Hub)](https://hub.docker.com/r/phlummox/android-studio) - -A Docker image designed to work with [Gitpod][gitpod], letting you run +A Docker image designed to work with Gitpod, letting you run Android Studio as a cloud-based IDE. -![Android studio running in the cloud](https://raw.githubusercontent.com/wiki/phlummox/android-studio-docker/using_images/studio-running.png) \ -  - -[gitpod]: https://www.gitpod.io/ ### Current status -- Works, but - -- doesn't persist settings/downloaded plugins/SDKs etc - -## Usage - -### Simple demo - -See the [wiki][wiki-using] for brief instructions on how to use this instance -in Gitpod on the web. +- experimental -[wiki-using]: https://github.com/phlummox/android-studio-docker/wiki/using ### Use with your own GitHub project diff --git a/build.py b/build.py new file mode 100755 index 0000000..973962c --- /dev/null +++ b/build.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 + +""" +Expected to have following env vars: + +IMAGE_NAME +IMAGE_VERSION +GH_IMAGE_ID +REPO_OWNER + +And a bunch of org.opencontainers.image metadata +assignments in a file "oc_labels". + +""" + +import os +import subprocess +import sys + +try: + repo_owner = os.environ["REPO_OWNER"] +except KeyError: + repo_owner = "phlummox" + +try: + image_name = os.environ["IMAGE_NAME"] +except KeyError: + image_name = "android-studio" + +version = os.environ["IMAGE_VERSION"] +gh_image_id = os.environ["GH_IMAGE_ID"] + +# org.opencontainers.image metadata +oc_labels = {} + +with open("oc_labels") as infile: + for line in infile.readlines(): + k, v = line.strip().split(sep="=", maxsplit=1) + oc_labels[k] = v + +# override version +oc_labels["org.opencontainers.image.version"] = version + +# org.label-schema metadata +ls_labels = { "org.label-schema.schema-version": "1.0", + "org.label-schema.build-date": oc_labels["org.opencontainers.image.created"], + "org.label-schema.name": f"{repo_owner}/{image_name}", + "org.label-schema.description": oc_labels["org.opencontainers.image.description"], + "org.label-schema.vcs-url": oc_labels["org.opencontainers.image.url"], + "org.label-schema.vcs-ref": oc_labels["org.opencontainers.image.revision"], + "org.label-schema.version": version } + +def verbose_run(cmd, **kwargs): + print("running: ", cmd, file=sys.stderr) + sys.stderr.flush() + sys.stdout.flush() + subprocess.run(cmd, **kwargs) + +# pull existing images if there + +cmd = ["docker", "pull", f"{gh_image_id}:{version}"] +verbose_run(cmd, check=False) + +## builder image +#cmd = f"""docker build --pull -f Dockerfile --target build +# --cache-from {gh_image_id}:{version}-builder +# -t {gh_image_id}:{version}-builder .""".split() +# +#verbose_run(cmd, check=True) + +# main image +cmd = f"""docker build --pull -f Dockerfile + --cache-from {gh_image_id}:{version}-builder + --cache-from {gh_image_id}:{version} + -t {gh_image_id}:{version}""".split() + +# build up --label args +for k in oc_labels: + val = oc_labels[k] + cmd += ["--label", f"{k}={val}"] + +for k in ls_labels: + val = ls_labels[k] + cmd += ["--label", f"{k}={val}"] + +cmd += ["."] + +verbose_run(cmd, check=True) +