Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #102 from sulochan/dockerfile
Browse files Browse the repository at this point in the history
Adds Dockerfile for craton inventory
  • Loading branch information
jimbaker committed Jun 28, 2016
2 parents 441a201 + 87f9823 commit 3f748e7
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

############################################################################
# Usage:
# docker build -t craton-inventory:latest .
# docker run --name craton-inventory -p 127.0.0.1:8080:8080 -d craton-inventory:latest
# curl http://127.0.0.1:8080/v1/regions -H "Content-Type: application/json" -H "X-Auth-Token: demo" -H "X-Auth-User: demo" -H "X-Auth-Project: 1"
#############################################################################

# Get Ubuntu base image
FROM ubuntu:16.04

# File Author / Maintainer
MAINTAINER Sulochan Acharya

# Install required software and tools
RUN apt-get update \
&& apt-get install -y \
gcc \
git \
curl \
build-essential \
python3.5 \
python3.5-dev

# Get pip
ADD https://bootstrap.pypa.io/get-pip.py /root/get-pip.py

# Install pip
RUN python3.5 /root/get-pip.py

# Install Mariadb
RUN apt-get install -y mariadb-server mariadb-client

# Install MySQL-python
RUN apt-get install -y libmysqlclient-dev python-mysqldb

# pip install virtualenv
RUN pip3 install virtualenv

# Expose port
EXPOSE 8080 3306

# Add Craton
ADD . /craton

# Init virutalenv
RUN virtualenv -p /usr/bin/python3.5 /craton

# Change Working Dir
WORKDIR /craton

# pip install mysql-python
RUN bin/pip install mysqlclient

# Install requirements
RUN bin/pip install -r /craton/requirements.txt

# Install Craton
RUN bin/pip install .

CMD ["tools/docker_run.sh"]
31 changes: 31 additions & 0 deletions tools/docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

/usr/bin/mysqld_safe > /dev/null 2>&1 &

RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MySQL service startup"
sleep 5
mysql -uroot -e "status" > /dev/null 2>&1
RET=$?
done

mysql -uroot -e "CREATE DATABASE craton CHARACTER SET = 'utf8'"
mysql -uroot -e "GRANT ALL PRIVILEGES ON craton.* TO 'craton'@'%' IDENTIFIED BY 'craton'"
mysqladmin flush-privileges

###############
# Run db-sync #
##############
/craton/bin/craton-inventory-dbsync --config-file=etc/inventory-api-conf.sample upgrade

###################################
# Create initial project and user #
###################################
mysql -u root craton -e "INSERT into projects (created_at, updated_at, name) values (NOW(), NOW(), 'demo')"
mysql -u root craton -e "INSERT into users (created_at, updated_at, project_id, username, api_key, is_admin) values (NOW(), NOW(), 1, 'demo', 'demo', False)"

#########################
# Start the API service #
#########################
/craton/bin/python3.5 /craton/craton/cmd/inventory-api.py --config-file=/craton/etc/inventory-api-conf.sample

0 comments on commit 3f748e7

Please sign in to comment.