THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

Add Docker support

feat/cockpit
Michał Czeraszkiewicz 5 years ago
parent
commit
56471c2fe4
  1. 1
      .dockerignore
  2. 22
      docker/Dockerfile
  3. 31
      docker/Dockerfile.development
  4. 26
      docker/scripts/build
  5. 14
      docker/scripts/build-development
  6. 15
      docker/scripts/run-development
  7. 12
      misc/make-deps.sh

1
.dockerignore

@ -0,0 +1 @@
docker

22
docker/Dockerfile

@ -0,0 +1,22 @@
FROM golang:1.6.2
MAINTAINER Michał Czeraszkiewicz <contact@czerasz.com>
# Set the reset cache variable
# Read more here: http://czerasz.com/2014/11/13/docker-tip-and-tricks/#use-refreshedat-variable-for-better-cache-control
ENV REFRESHED_AT 2016-05-10
# Update the package list to be able to use required packages
RUN apt-get update
# Change the working directory
WORKDIR /go/src/mgmt
# Copy all the files to the working directory
COPY . /go/src/mgmt
# Install dependencies
RUN make deps
# Build the binary
RUN make build

31
docker/Dockerfile.development

@ -0,0 +1,31 @@
FROM golang:1.6.2
MAINTAINER Michał Czeraszkiewicz <contact@czerasz.com>
# Set the reset cache variable
# Read more here: http://czerasz.com/2014/11/13/docker-tip-and-tricks/#use-refreshedat-variable-for-better-cache-control
ENV REFRESHED_AT 2016-05-14
RUN apt-get update
# Setup User to match Host User
# Give the nre user superuser permissions
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG USER_NAME=mgmt
ARG GROUP_NAME=$USER_NAME
RUN groupadd --gid $GROUP_ID $GROUP_NAME && \
useradd --create-home --home /home/$USER_NAME --uid ${USER_ID} --gid $GROUP_NAME --groups sudo $USER_NAME && \
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# Copy all the files to the working directory
COPY . /home/$USER_NAME/mgmt
# Change working directory
WORKDIR /home/$USER_NAME/mgmt
# Install dependencies
RUN make deps
# Change user
USER ${USER_NAME}

26
docker/scripts/build

@ -0,0 +1,26 @@
#!/bin/bash
script_directory="$( cd "$( dirname "$0" )" && pwd )"
project_directory=$script_directory/../..
# Specify the Docker image name
image_name='purpleidea/mgmt'
# Build the image which contains the compiled binary
docker build -t $image_name \
--file=$project_directory/docker/Dockerfile $project_directory
# Remove the container if it already exists
docker rm -f mgmt-export 2> /dev/null
# Start the container in background so we can "copy out" the binary
docker run -d --name=mgmt-export $image_name bash -c 'while true; sleep 1000; done'
# Remove the current binary
rm $project_directory/mgmt 2> /dev/null
# Get the binary from the container
docker cp mgmt-export:/go/src/mgmt/mgmt $project_directory/mgmt
# Remove the container
docker rm -f mgmt-export 2> /dev/null

14
docker/scripts/build-development

@ -0,0 +1,14 @@
#!/bin/bash
# Stop on any error
set -e
script_directory="$( cd "$( dirname "$0" )" && pwd )"
project_directory=$script_directory/../..
# Specify the Docker image name
image_name='purpleidea/mgmt:development'
# Build the image
docker build -t $image_name \
--file=$project_directory/docker/Dockerfile.development $project_directory

15
docker/scripts/run-development

@ -0,0 +1,15 @@
#!/bin/bash
# Stop on any error
set -e
script_directory="$( cd "$( dirname "$0" )" && pwd )"
project_directory=$script_directory/../..
# Specify the Docker image name
image_name='purpleidea/mgmt:development'
# Run container in development mode
docker run --rm --name=mgm_development --user=mgmt \
-v $project_directory:/home/mgmt/mgmt \
-it $image_name bash

12
misc/make-deps.sh

@ -9,6 +9,8 @@ if env | grep -q '^TRAVIS=true$'; then
travis=1
fi
sudo_command=$(which sudo)
if [ $travis -eq 0 ]; then
YUM=`which yum 2>/dev/null`
APT=`which apt-get 2>/dev/null`
@ -18,15 +20,15 @@ if [ $travis -eq 0 ]; then
fi
if [ ! -z "$YUM" ]; then
# some go dependencies are stored in mercurial
sudo $YUM install -y golang golang-googlecode-tools-stringer hg
$sudo_command $YUM install -y golang golang-googlecode-tools-stringer hg
fi
if [ ! -z "$APT" ]; then
sudo $APT update
sudo $APT install -y golang make gcc packagekit mercurial
$sudo_command $APT update
$sudo_command $APT install -y golang make gcc packagekit mercurial
# one of these two golang tools packages should work on debian
sudo $APT install -y golang-golang-x-tools || true
sudo $APT install -y golang-go.tools || true
$sudo_command $APT install -y golang-golang-x-tools || true
$sudo_command $APT install -y golang-go.tools || true
fi
fi

Loading…
Cancel
Save