手动build unity3d的docker镜像

参考资料

本机build

  • 因为gableroux/unity3d默认版本只包括了windowslinuxmacwebgl平台,然后将androidios分为了两个不同的镜像,我就想把他们整合成一个镜像
  • 这里以unity2017.4.8f1为例,参考:unitysetup_2017-android.Dockerfile · master · Gabriel Le Breton / unity3d · GitLab,直接上修改后的Dockerfile,肯定是基于gableroux/unity3d:2017.4.8f1现有的轮子,再添加iosandroid的组件,以及android的环境就好,因为没有删掉多余的东西感觉直接使用ubuntu的镜像也可以,资源的下载链接和sha1可以在论坛里面找到
FROM gableroux/unity3d:2017.4.8f1

ARG DOWNLOAD_URL=https://beta.unity3d.com/download/8140fe378247/UnitySetup-2017.4.8f1
ARG SHA1=119ec24433cf9e94ead7d62e64b69cec686d5aa5
ARG COMPONENTS=iOS,Android

ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true

RUN echo "America/New_York" > /etc/timezone && \
    apt-get update -qq; \
    apt-get install -qq -y \
    gconf-service \
    lib32gcc1 \
    lib32stdc++6 \
    libasound2 \
    libarchive13 \
    libc6 \
    libc6-i386 \
    libcairo2 \
    libcap2 \
    libcups2 \
    libdbus-1-3 \
    libexpat1 \
    libfontconfig1 \
    libfreetype6 \
    libgcc1 \
    libgconf-2-4 \
    libgdk-pixbuf2.0-0 \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libglu1-mesa \
    libgtk2.0-0 \
    libgtk3.0 \
    libnotify4 \
    libnspr4 \
    libnss3 \
    libpango1.0-0 \
    libsoup2.4-1 \
    libstdc++6 \
    libx11-6 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxi6 \
    libxrandr2 \
    libxrender1 \
    libxtst6 \
    libunwind-dev \
    zlib1g \
    pulseaudio \
    debconf \
    npm \
    xdg-utils \
    lsb-release \
    libpq5 \
    xvfb \
    wget \
    locales \
    software-properties-common \
    unzip \
    && add-apt-repository ppa:openjdk-r/ppa \
    && add-apt-repository ppa:cwchien/gradle \
    && apt-get install -qq -y \
    gradle \
    openjdk-8-jdk \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8


# Setup Android SDK/JDK Environment Variables
ENV ANDROID_SDK_VERSION ${ANDROID_SDK_VERSION:-28}
ENV ANDROID_SDK_COMPONENTS platforms;android-$ANDROID_SDK_VERSION
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre/
ENV PATH ${PATH}:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin
ENV ANDROID_HOME /opt/android-sdk-linux

ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
ENV LANG en_US.UTF-8

# Install Android SDK Installer...
RUN cd /opt && \
    wget -q https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -O android-sdk.zip && \
    unzip -q android-sdk.zip -d android-sdk-linux && \
    rm -f android-sdk.zip && \
    ls -ahl android-sdk-linux

RUN chmod -R 755 .${ANDROID_HOME}/tools/*

# Install Android SDK
RUN ${ANDROID_HOME}/tools/bin/sdkmanager ${ANDROID_SDK_COMPONENTS}

# accept license
RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses

RUN gradle -v

RUN wget -nv ${DOWNLOAD_URL} -O UnitySetup && \
    # compare sha1 if given
    if [ -n "${SHA1}" -a "${SHA1}" != "" ]; then \
      echo "${SHA1}  UnitySetup" | sha1sum --check -; \
    else \
      echo "no sha1 given, skipping checksum"; \
    fi && \
    # make executable
    chmod +x UnitySetup && \
    # 2017 difference: must have /tmp/ and /opt/unity/ folders before installation
    mkdir -p /tmp/unity && \
    mkdir -p /opt/Unity && \
    # agree with license
    echo y | \
    # install unity with required components
    xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
    ./UnitySetup \
    --unattended \
    --install-location=/opt/Unity \
    --verbose \
    --download-location=/tmp/unity \
    --components=$COMPONENTS && \
    # make a directory for the certificate Unity needs to run
    mkdir -p /root/.local/share/unity3d/Certificates/ && \
    # remove setup & temp files
    rm UnitySetup && \
    rm -rf /tmp/unity && \
    rm -rf /root/.local/share/Trash/* && \
    # android specific paths
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /tmp/* && \
    rm -rf /var/tmp/*
  • 使用docker build开始构建镜像,这里除了普通的命令,添加了HTTP_PROXYHTTPS_PROXY来做代理,android的sdk被墙了,还可以理解,不知到为什么unity3d的一部分链接也无法访问了,都需要添加代理才行。docker build会在一个容器内执行,--network host才是指定你是通过宿主机去访问代理的
#build images
docker build -t wanderer/unity3d:2017.4.8f1-full --build-arg HTTP_PROXY=http://192.168.1.72:2080 --build-arg HTTPS_PROXY=https://192.168.1.72:2080 --network host ./

阿里云build

  • 在某些环境使用代理build并不一定方便,在我找docker国内镜像的时候,发现了阿里云-上云就上阿里云可以选择利用海外服务器进行build,这也是不错的选择了
  • 登录阿里云,并在个人中心里面找到容器镜像服务,然后选择创建镜像仓库,只需要记得勾选海外服务器构建就可以了。
  • 我的Dockerfile文件是通过github与阿里云绑定的,当然也可以选择他方式
  • Dockerfile文件里面,就不能继承gableroux/unity3d了,阿里云没有这个镜像,只有继承ubuntu就好了
FROM ubuntu:18.04

ARG DOWNLOAD_URL=https://beta.unity3d.com/download/8140fe378247/UnitySetup-2017.4.8f1
ARG SHA1=119ec24433cf9e94ead7d62e64b69cec686d5aa5
ARG COMPONENTS=Unity,Windows,Windows-Mono,WebGL,Mac,Mac-Mono,iOS,Android

ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true

RUN echo "America/New_York" > /etc/timezone && \
    apt-get update -qq; \
    apt-get install -qq -y \
    gconf-service \
    lib32gcc1 \
    lib32stdc++6 \
    libasound2 \
    libarchive13 \
    libc6 \
    libc6-i386 \
    libcairo2 \
    libcap2 \
    libcups2 \
    libdbus-1-3 \
    libexpat1 \
    libfontconfig1 \
    libfreetype6 \
    libgcc1 \
    libgconf-2-4 \
    libgdk-pixbuf2.0-0 \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libglu1-mesa \
    libgtk2.0-0 \
    libgtk3.0 \
    libnotify4 \
    libnspr4 \
    libnss3 \
    libpango1.0-0 \
    libsoup2.4-1 \
    libstdc++6 \
    libx11-6 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxi6 \
    libxrandr2 \
    libxrender1 \
    libxtst6 \
    libunwind-dev \
    zlib1g \
    pulseaudio \
    debconf \
    npm \
    xdg-utils \
    lsb-release \
    libpq5 \
    xvfb \
    wget \
    locales \
    software-properties-common \
    unzip \
    && add-apt-repository ppa:openjdk-r/ppa \
    && add-apt-repository ppa:cwchien/gradle \
    && apt-get install -qq -y \
    gradle \
    openjdk-8-jdk \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

# Setup Android SDK/JDK Environment Variables
ENV ANDROID_SDK_VERSION ${ANDROID_SDK_VERSION:-28}
ENV ANDROID_SDK_COMPONENTS platforms;android-$ANDROID_SDK_VERSION
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre/
ENV PATH ${PATH}:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin
ENV ANDROID_HOME /opt/android-sdk-linux

ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
ENV LANG en_US.UTF-8

# Install Android SDK Installer...
RUN cd /opt && \
    wget -q https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -O android-sdk.zip && \
    unzip -q android-sdk.zip -d android-sdk-linux && \
    rm -f android-sdk.zip && \
    ls -ahl android-sdk-linux

RUN chmod -R 755 .${ANDROID_HOME}/tools/*

# Install Android SDK
RUN ${ANDROID_HOME}/tools/bin/sdkmanager ${ANDROID_SDK_COMPONENTS}

# accept license
RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses

RUN gradle -v

RUN wget -nv ${DOWNLOAD_URL} -O UnitySetup && \
    # compare sha1 if given
    if [ -n "${SHA1}" -a "${SHA1}" != "" ]; then \
      echo "${SHA1}  UnitySetup" | sha1sum --check -; \
    else \
      echo "no sha1 given, skipping checksum"; \
    fi && \
    # make executable
    chmod +x UnitySetup && \
    # 2017 difference: must have /tmp/ and /opt/unity/ folders before installation
    mkdir -p /tmp/unity && \
    mkdir -p /opt/Unity && \
    # agree with license
    echo y | \
    # install unity with required components
    xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
    ./UnitySetup \
    --unattended \
    --install-location=/opt/Unity \
    --verbose \
    --download-location=/tmp/unity \
    --components=$COMPONENTS && \
    # make a directory for the certificate Unity needs to run
    mkdir -p /root/.local/share/unity3d/Certificates/ && \
    # remove setup & temp files
    rm UnitySetup && \
    rm -rf /tmp/unity && \
    rm -rf /root/.local/share/Trash/* && \
    # android specific paths
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /tmp/* && \
    rm -rf /var/tmp/*

ADD CACerts.pem /root/.local/share/unity3d/Certificates/
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐