-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile.ubuntu
134 lines (115 loc) · 5.8 KB
/
Dockerfile.ubuntu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This dockerfile creates a container with all tools required to access and
# manage intances and containers at the google cloud platform with
# ansible and terraform
#
# Author Daniel Porto
FROM ubuntu:artful
LABEL maintainer="daniel.porto@gmail.com"
#-----------------------------------------------------------------------------
# install dependencies
#-----------------------------------------------------------------------------
# install tools for managing ppa repositories
RUN apt update \
&& apt -y install software-properties-common \
unzip \
vim \
curl \
tmux \
git \
sudo \
gawk \
&& rm -rf /var/lib/apt/lists/*
#-----------------------------------------------------------------------------
# install google cloud platform and kubernetes client
#-----------------------------------------------------------------------------
# Create an environment variable for the correct distribution
RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" \
# Add the Cloud SDK distribution URI as a package source
&& echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
# Import the Google Cloud Platform public key
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \
# add google cloud sdk
# && apt install -y --allow-unauthenticated google-cloud-sdk \
&& apt update \
&& apt install -y google-cloud-sdk \
# kubectl \
&& rm -rf /var/lib/apt/lists/*
#-----------------------------------------------------------------------------
# install ansible
#-----------------------------------------------------------------------------
# add extra repositories
RUN apt-add-repository -y ppa:ansible/ansible \
&& apt update \
# add deployment management tool
&& apt install -y ansible \
&& rm -rf /var/lib/apt/lists/*
#-----------------------------------------------------------------------------
# install terraform
#-----------------------------------------------------------------------------
RUN curl -O https://releases.hashicorp.com/terraform/0.11.2/terraform_0.11.2_linux_amd64.zip \
&& unzip terraform_0.11.2_linux_amd64.zip -d /usr/local/bin \
&& rm terraform_0.11.2_linux_amd64.zip
# some extra packages for drawing the infrastructure
# RUN apt update \
# # add graph builder tool for terraform
# && apt install -y graphviz \
# && rm -rf /var/lib/apt/lists/*
#-----------------------------------------------------------------------------
# install locales, required for scripts
#-----------------------------------------------------------------------------
# some scripts require locale to be properly set
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
#-----------------------------------------------------------------------------
# install zshell and dotfiles
#-----------------------------------------------------------------------------
# install zsh with a some plugins
RUN apt update && apt install -y zsh && rm -rf /var/lib/apt/lists/* \
# && git clone https://github.com/danielporto/zsh-dotfiles.git $HOME/dotfiles && $HOME/dotfiles/install \
# # define zsh as default shell
# && chsh -s $(which zsh) \
# # install zsh plugins
# && export TERM=dumb && /usr/bin/zsh -ic 'exit' < /dev/null
&& chsh -s $(which zsh)
#-----------------------------------------------------------------------------
# configuring cloud environment - depends on zshell above
#-----------------------------------------------------------------------------
# add the content into the container.
COPY . /gcloud
WORKDIR /gcloud
RUN chmod +x /gcloud/*.sh
# # cloud environment variables
# RUN echo "source /gcloud/envs.sh" >> $HOME/dotfiles/zshrc \
# && echo "source /gcloud/load-credentials.sh" >> $HOME/dotfiles/zshrc
# add support for terraform dynamic inventory
ADD https://github.com/nbering/terraform-inventory/releases/download/v1.0.1/terraform.py /usr/local/bin/
ADD https://github.com/nbering/terraform-provider-ansible/releases/download/v0.0.3/terraform-provider-ansible-linux_amd64.zip .
RUN unzip terraform-provider-ansible-linux_amd64.zip && rm -f terraform-provider-ansible-linux_amd64.zip \
&& mkdir -p .terraform/plugins \
&& rsync -a linux_amd64 .terraform/plugins/ \
&& rm -rf linux_amd64 \
&& chmod +x /gcloud/*.sh && chmod o+rx /usr/local/bin/terraform.py
# some instances does not allow root login, thus start with a regular one.
RUN useradd -c 'cloud user' -m -d /home/cloudusr -s /usr/bin/zsh cloudusr \
&& echo "cloudusr ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
&& chown -R cloudusr.cloudusr /gcloud
# switch user to install zsh with a some plugins
USER cloudusr
ENV HOME /home/cloudusr
RUN git clone https://github.com/danielporto/zsh-dotfiles.git $HOME/dotfiles \
# cloud environment variables
&& echo "source /gcloud/envs.sh" >> $HOME/dotfiles/zshrc \
&& echo "source /gcloud/load-credentials.sh" >> $HOME/dotfiles/zshrc
RUN $HOME/dotfiles/install
# install zsh plugins - it can fail due to download problems
# and require you to re-run the build command.
# Thus better run in a separate layer for caching
RUN export TERM=dumb \
&& zsh -ic 'exit' < /dev/null \
&& echo "Finished"
#-----------------------------------------------------------------------------
# default terminal configuration and customization
#-----------------------------------------------------------------------------
# open a tmux terminal or reattach whenever the container starts
CMD ["tmux", "new-session", "-A", "-s main"]