Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Build/Push CI #875

Merged
merged 17 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .docker/docker_start_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
#Configure web server

# cd /usr/src/app/e-mission-server
shankari marked this conversation as resolved.
Show resolved Hide resolved

#set database URL using environment variable
echo ${DB_HOST}
if [ -z ${DB_HOST} ] ; then
local_host=`hostname -i`
sed "s_localhost_${local_host}_" conf/storage/db.conf.sample > conf/storage/db.conf
else
sed "s_localhost_${DB_HOST}_" conf/storage/db.conf.sample > conf/storage/db.conf
fi
cat conf/storage/db.conf

#set Web Server host using environment variable
echo ${WEB_SERVER_HOST}
if [ -z ${WEB_SERVER_HOST} ] ; then
local_host=`hostname -i`
sed "s_localhost_${local_host}_" conf/net/api/webserver.conf.sample > conf/net/api/webserver.conf
else
sed "s_localhost_${WEB_SERVER_HOST}_" conf/net/api/webserver.conf.sample > conf/net/api/webserver.conf
fi
cat conf/net/api/webserver.conf

if [ -z ${LIVERELOAD_SRC} ] ; then
echo "Live reload disabled, "
else
echo "Enabling bottle live reload"
ORIG="run.host=server_host"
NEW="run(reloader=True,host=server_host"
echo "Replacing $ORIG -> $NEW"
sed -i -e "s|$ORIG|$NEW|g" /usr/src/app/e-mission-server/emission/net/api/cfc_webapp.py
fi

#TODO: start cron jobs
# change python environment
source setup/activate.sh

# launch the webapp
./e-mission-py.bash emission/net/api/cfc_webapp.py
24 changes: 24 additions & 0 deletions .docker/setup_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
echo "About to start conda update, this may take some time..."
source setup/setup_conda.sh Linux-x86_64
source setup/setup.sh
conda clean -t
conda clean -p

if [ -d "webapp/www/" ]; then
cp /index.html webapp/www/index.html
fi

if [ -d "/conf" ]; then
echo "Found configuration, overriding..."
cp -r /conf/* conf/
fi

shankari marked this conversation as resolved.
Show resolved Hide resolved
if [ -z ${LIVERELOAD_SRC} ] ; then
echo "Live reload disabled, "
else
echo "Enabling bottle live reload"
ORIG="run.host=server_host"
NEW="run(reloader=True,host=server_host"
echo "Replacing $ORIG -> $NEW"
sed -i -e "s|$ORIG|$NEW|g" emission/net/api/cfc_webapp.py
fi
48 changes: 48 additions & 0 deletions .github/workflows/image_build_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This is a basic workflow to help you get started with Actions

name: docker image

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master, gis-based-mode-detection, join_redirect_to_static ]


# Env variable
env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: docker login
run: | # log into docker hub account
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD

- name: Get current date # get the date of the build
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d--%M-%S')"

#Runs a single command using the runners shell
- name: Run a one-line script
run: echo running in repo ${GITHUB_REPOSITORY#*/} branch ${GITHUB_REF##*/} on ${{ steps.date.outputs.date }}

# Runs a set of commands using the runners shell
- name: build docker image
run: |
docker build -t $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} .
docker images

- name: push docker image
run: |
docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }}
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# python 3
FROM ubuntu:focal

MAINTAINER K. Shankari (shankari@eecs.berkeley.edu)

WORKDIR /usr/src/app

RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git

# install nano and vim for editing
RUN apt-get -y install nano vim

# cleanup
RUN apt-get -y remove --purge build-essential
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY . .

# ARG SERVER_REPO
# ENV SERVER_REPO=${SERVER_REPO:-https://github.com/e-mission/e-mission-server.git}

# ARG SERVER_BRANCH
# ENV SERVER_BRANCH=${SERVER_BRANCH:-master}

# ADD clone_server.sh /clone_server.sh
RUN chmod u+x ./.docker/setup_config.sh
# ADD index.html /index.html
shankari marked this conversation as resolved.
Show resolved Hide resolved

# # This clone puts the server code into the image, not the container
RUN bash -c "./.docker/setup_config.sh"

# #declare environment variables
ENV DB_HOST=''
ENV WEB_SERVER_HOST=''

ENV LIVERELOAD_SRC=''
RUN chmod u+x ./.docker/docker_start_script.sh

EXPOSE 8080

CMD ["/bin/bash", "./.docker/docker_start_script.sh"]