-
Notifications
You must be signed in to change notification settings - Fork 3
/
.dockerfunc
153 lines (133 loc) · 3.83 KB
/
.dockerfunc
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
#
# Inspired (and in some cases, like the helper functions, straight copied) from
# [jessfraz/dotfiles][1] (see license at end of file), this is a bunch of Bash
# wrappers for docker run commands.
#
# [1]: https://github.com/jessfraz/dotfiles/blob/9ac223d3d866dc326701cf5b7b32b196177ec1f2/.dockerfunc
#
# Helper Functions
# via jessfraz/dotfiles
#
dcleanup(){
local containers
containers=( $(docker ps -aq 2>/dev/null) )
docker rm "${containers[@]}" 2>/dev/null
local volumes
volumes=( $(docker ps --filter status=exited -q 2>/dev/null) )
docker rm -v "${volumes[@]}" 2>/dev/null
local images
images=( $(docker images --filter dangling=true -q 2>/dev/null) )
docker rmi "${images[@]}" 2>/dev/null
}
del_stopped(){
local name=$1
local state
state=$(docker inspect --format "{{.State.Running}}" "$name" 2>/dev/null)
if [[ "$state" == "false" ]]; then
docker rm "$name"
fi
}
relies_on(){
for container in "$@"; do
local state
state=$(docker inspect --format "{{.State.Running}}" "$container" 2>/dev/null)
if [[ "$state" == "false" ]] || [[ "$state" == "" ]]; then
echo "$container is not running, starting it for you."
$container
fi
done
}
#
# Container Aliases
#
keybase() {
docker run --rm -it \
-v "${HOME}/.config/keybase:/home/keybase/.config/keybase" \
--name keybase \
langrisha/keybase:1.0.0 "$@"
}
pandoc() {
pandoc_version="2.9.2.1"
docker run --rm \
--volume "`pwd`:/data" \
--user `id -u`:`id -g` \
pandoc/latex:$pandoc_version \
"$@"
}
rails-new() {
mkdir $1
pushd $1
cat > Gemfile <<EOL
source 'https://rubygems.org'
gem 'rails'
EOL
touch Gemfile.lock
cat > Dockerfile <<EOL
FROM andrewsardone/docker-rails-dev
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY . /app
EOL
cat > docker-compose.yml <<EOL
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
EOL
docker-compose run web rails new . --force --database=postgresql
popd
}
# CLI for the Zeit Now deployment PaaS
# https://zeit.co/now
now() {
local directory_name=$(basename "$PWD")
docker-now() {
docker run --rm -it \
-v $PWD:/now \
andrewsardone/docker-zeit-now \
"$@"
}
if [ $# -eq 0 ]; then
# Since we're always deploying from the same directory of /now within the
# container, we'll pass in our host's directory as the name of the
# application to be deployed.
docker-now now -n $directory_name
else
docker-now now "$@"
fi
}
# License for https://github.com/jessfraz/dotfiles
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Jessie Frazelle
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.