How do you make a docker image to deploy AI2?

Hi, I am trying to make a docker image that can deploy AI2 anywhere, I have currently tried

Dockerfile:

FROM openjdk:8

ENV HOME /home/developer

RUN ls

# Install other useful tools
RUN apt-get update && apt-get install -y \
ant \
curl \
git \
sudo \
unzip \
# Install dependency
	lib32z1 \
	lib32stdc++6 \
# Install phantomJS
phantomjs \
# Clean up
 && apt-get clean && apt-get purge \
# Set up some permissions. Replace 1000 with your user/groupid if it is different
 && export uid=1000 gid=1000 \
 && mkdir -p $HOME \
 && echo "developer:x:${uid}:${gid}:Developer,,,:${HOME}:/bin/bash" >> /etc/passwd \
 && echo "developer:x:${uid}:" >> /etc/group \
 && echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer \
 && chmod 0440 /etc/sudoers.d/developer \
 && chown ${uid}:${gid} -R $HOME \
# Google App engine
 && curl 'https://storage.googleapis.com/appengine-sdks/featured/appengine-java-sdk-1.9.84.zip' > /tmp/appengine.zip \
 && unzip -d $HOME /tmp/appengine.zip \
 && rm /tmp/appengine.zip \
 && ln -s $HOME/appengine-java-sdk-1.9.84 $HOME/appengine

COPY server.sh $HOME
RUN chmod +x $HOME/server.sh \
 && chown ${uid}:${gid} $HOME/server.sh

EXPOSE 8888

USER developer
WORKDIR $HOME

startServer.sh

#!/bin/bash
set -e

cd /home/developer/appinventor-sources/appinventor

ant RunLocalBuildServer > /dev/null &

/home/developer/appengine/bin/dev_appserver.sh --port=8888 --address=0.0.0.0 appengine/build/war/

Any help is appreciated :slight_smile:

4 Likes

There are some things you could leave out. You don't need phantomjs, for example. In reality, what you'd probably want to do is use a gcloud SDK instead since the standalone App Engine SDK is deprecated.

I also don't see where you're adding the compiled binaries to your image, so your startServer.sh script will likely fail.

3 Likes

Maybe this will hep you

PS : @Hrichik_Mazumder Succeeded to do so,
https://ai2.up.railway.app

Hi @ewpatton,
I made a GitHub action that builds the appinventor, then builds the docker image and pushes it to the docker registry. The server.sh and dockerfile below are for just the frontend and gwt parts except for the build server. To run the build server, the last line of the server.sh needs to be replaced by ant RunLocalBuildServer and the EXPOSE 8888 in dockerfile be replaced with EXPOSE 9990 and the dockerfile needs to be built again.

.github/workflows/docker-image.yml:

name: Build UI

on: [workflow_dispatch]

jobs:
  build_push_docker:
name: Push Docker image to Docker Hub after building
runs-on: ubuntu-latest
steps:
  - name: Check out the repo
    uses: actions/checkout@v2
  
  - name: 'Set up JDK 1.8'
    uses: actions/setup-java@v1
    with:
      java-version: 8
      
  - name: 'Checkout submodules'
    uses: textbook/git-checkout-submodule-action@master
    
  - name: 'Install 32-bit dependencies'
    run: sudo apt-get install -y libc6-i386 lib32z1 lib32stdc++6 ant
    
  - name: 'Make Auth Key'
    run: ant MakeAuthKey
    
    working-directory: appinventor
  - name: 'Build Appinventor'
    run: ant noplay        
    working-directory: appinventor

  
  - name: Log in to Docker Hub
    uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
    with:
      username: ${{ secrets.DH_USERNAME }}
      password: ${{ secrets.DH_PASSWORD }}
  
  - name: Extract metadata (tags, labels) for Docker
    id: meta
    uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
    with:
      images: ${{ secrets.DH_USERNAME }}/ai2
      
  - name: Build and push Docker image
    uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
    with:
      context: .
      push: true
      tags: ${{ secrets.DH_USERNAME }}/ai2:${{ github.sha }}
      labels: ${{ secrets.DH_USERNAME }}/ai2:${{ github.sha }}

Dockerfile:

FROM openjdk:8 
 
ENV HOME /home/developer 
 
WORKDIR $HOME 
 
COPY . . 
 
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg  add - && apt-get update -y && apt-get install google-cloud-sdk -y 
 
RUN apt-get install -y  ant 
 
RUN curl 'https://storage.googleapis.com/appengine-sdks/featured/appengine-java-sdk-1.9.84.zip' > /tmp/appengine.zip \ 
 && unzip -d $HOME /tmp/appengine.zip \ 
 && rm /tmp/appengine.zip \ 
 && ln -s $HOME/appengine-java-sdk-1.9.84 $HOME/appengine 

EXPOSE 8888 
 
RUN ls 
 
CMD chmod 777  server.sh && ./server.sh

server.sh:

#!/bin/bash
set -e

cd appinventor

/home/developer/appengine/bin/dev_appserver.sh --port=8888 --address=0.0.0.0 appengine/build/war/