Skip to content

Commit 22cdd6a

Browse files
authored
Merge pull request #44 from manala/lazy.symfony/deploy
[Lazy - Symfony] Deploy
2 parents 40ab1b3 + 4a239dd commit 22cdd6a

File tree

8 files changed

+153
-12
lines changed

8 files changed

+153
-12
lines changed

lazy.symfony/.manala.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
manala:
22
description: Symfony environment, opiniated, docker based, for lazy people
33
sync:
4+
- .manala/ansistrano
5+
- .manala/docker
46
- .manala/make
57
- .manala/mariadb
68
- .manala/nginx
@@ -44,3 +46,14 @@ system:
4446
# @option {"label": "MariaDB version"}
4547
# @schema {"enum": [null, 10.4]}
4648
version: ~
49+
50+
##########
51+
# Deploy #
52+
##########
53+
54+
deploy:
55+
inventory: {}
56+
shared_paths: []
57+
shared_files: []
58+
hooks:
59+
before_symlink: []

lazy.symfony/.manala/Dockerfile.tmpl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,23 @@ WORKDIR /srv
8888

8989
FROM base AS app
9090

91-
ARG PHP_VERSION={{ .Vars.system.php.version | toString }}
92-
9391
# Disable irrelevants apt-key warnings
9492
ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1
9593
# Disable all debian user interaction
9694
ARG DEBIAN_FRONTEND=noninteractive
9795

96+
{{- if .Vars.deploy.inventory }}
97+
RUN \
98+
apt-get install --yes --no-install-recommends \
99+
openssh-client \
100+
ansible \
101+
&& ansible-galaxy install --roles-path /usr/share/ansible/roles \
102+
ansistrano.deploy,3.5.1 \
103+
ansistrano.rollback,3.0.0
104+
105+
COPY docker/etc/ssh_config /etc/ssh/ssh_config
106+
{{- end }}
107+
98108
{{- if .Vars.system.nodejs.version }}
99109

100110
ARG NODE_VERSION={{ .Vars.system.nodejs.version | toString }}
@@ -116,7 +126,8 @@ RUN \
116126

117127
{{- end }}
118128

119-
# Php
129+
ARG PHP_VERSION={{ .Vars.system.php.version | toString }}
130+
120131
RUN \
121132
echo "deb https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/php.list \
122133
&& curl --silent --location --show-error https://packages.sury.org/php/apt.gpg \
@@ -150,4 +161,8 @@ STOPSIGNAL SIGQUIT
150161

151162
EXPOSE 9000
152163

164+
COPY docker/bin/entrypoint.sh /usr/local/bin/entrypoint.sh
165+
166+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
167+
153168
CMD ["php-fpm{{ .Vars.system.php.version | toString }}"]

lazy.symfony/.manala/Makefile.tmpl

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ HELP += $(call help,up, Create and start environment (BUILD))
2424
up:
2525
$(call message,Create and start environment...)
2626
mkdir -p $(_ROOT_DIR)/.manala/.cache
27-
OS=$(OS) docker-compose up \
28-
$(if $(BUILD),--build --remove-orphans)
27+
OS=$(OS) \
28+
$(if $(OS_DARWIN),SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock) \
29+
docker-compose up \
30+
$(if $(BUILD),--build --remove-orphans)
2931

3032
HELP += $(call help,clean, Clean environment)
3133
clean:
3234
$(call confirm,Please$(,) confirm environment cleaning)
33-
OS=$(OS) docker-compose down \
34-
--rmi all \
35-
--volumes \
36-
--remove-orphans
35+
OS=$(OS) \
36+
docker-compose down \
37+
--rmi all \
38+
--volumes \
39+
--remove-orphans
3740

3841
HELP += $(call help,sh, Shell environment)
3942
sh:
@@ -48,14 +51,48 @@ sh.nginx:
4851
nginx \
4952
bash
5053

54+
{{- if .Vars.system.mariadb.version }}
55+
5156
HELP += $(call help,sh.mariadb,Shell environment - MariaDB)
5257
sh.mariadb:
5358
docker-compose exec \
5459
mariadb \
5560
bash
5661

62+
{{- end }}
63+
5764
endif
5865

66+
{{- if .Vars.deploy.inventory }}
67+
68+
##########
69+
# Deploy #
70+
##########
71+
72+
HELP += $(call help_section, Deploy)
73+
74+
{{- range $group, $hosts := .Vars.deploy.inventory }}
75+
{{- range $host, $vars := $hosts }}
76+
77+
HELP += $(call help,ssh@{{ $host }}, Ssh to {{ $host }})
78+
ssh@{{ $host }}:
79+
ssh {{ $vars.user }}@{{ $vars.host }}
80+
81+
{{- end }}
82+
{{- end }}
83+
84+
{{- range $group, $hosts := .Vars.deploy.inventory }}
85+
86+
HELP += $(call help,deploy@{{ $group }}, Deploy to {{ $group }})
87+
deploy@{{ $group }}:
88+
ansible-playbook $(_ROOT_DIR)/.manala/ansistrano/playbook.yaml \
89+
--inventory $(_ROOT_DIR)/.manala/ansistrano/inventory.yaml \
90+
--limit {{ $group}}
91+
92+
{{- end }}
93+
94+
{{- end }}
95+
5996
#######
6097
# App #
6198
#######
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{{- with .Vars.deploy -}}
2+
3+
---
4+
5+
{{- if .inventory }}
6+
7+
all:
8+
9+
vars:
10+
ansistrano_allow_anonymous_stats: false
11+
ansistrano_deploy_via: rsync
12+
ansistrano_deploy_from: ../..
13+
# Shared
14+
{{- if .shared_paths }}
15+
ansistrano_shared_paths: {{ .shared_paths | toYaml | nindent 10 }}
16+
{{- end }}
17+
{{- if .shared_files }}
18+
ansistrano_shared_files: {{ .shared_files | toYaml | nindent 10 }}
19+
{{- end }}
20+
# Hooks
21+
{{- if .hooks.before_symlink }}
22+
ansistrano_before_symlink_tasks_file: hooks/before_symlink.yaml
23+
{{- end }}
24+
25+
children:
26+
27+
{{- range $group, $hosts := .inventory }}
28+
{{ $group }}:
29+
hosts:
30+
{{- range $host, $vars := $hosts }}
31+
{{ $host }}:
32+
ansible_host: {{ $vars.host }}
33+
ansible_user: {{ $vars.user }}
34+
ansistrano_deploy_to: {{ $vars.dir }}
35+
{{- end }}
36+
{{- end }}
37+
38+
{{- end }}
39+
40+
{{- end }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
3+
- hosts: all
4+
roles:
5+
- role: ansistrano.deploy

lazy.symfony/.manala/docker-compose.yaml.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ services:
9090
- ./php/app.ini:/etc/php/{{ .Vars.system.php.version | toString }}/fpm/conf.d/php.ini:ro
9191
- ./php/xdebug/${OS}.ini:/etc/php/{{ .Vars.system.php.version | toString }}/fpm/conf.d/xdebug.ini:ro
9292
- ./php/fpm.conf:/etc/php/{{ .Vars.system.php.version | toString }}/fpm/pool.d/zz-www.conf:ro
93-
- ./starship/config.toml:/etc/starship/config.toml:ro
9493
- ..:/srv:cached
94+
- ${SSH_AUTH_SOCK:-/dev/null}:${SSH_AUTH_SOCK:-/tmp/null}
9595
links:
9696
- maildev
9797
{{- if .Vars.system.mariadb.version }}
9898
- mariadb
9999
{{- end }}
100100
environment:
101-
- STARSHIP_CONFIG=/etc/starship/config.toml
101+
- STARSHIP_CONFIG=/srv/.manala/starship/config.toml
102102
- XDG_CACHE_HOME=/srv/.manala/.cache
103-
- HISTFILE=/srv/.manala/.cache/.bash_history
103+
- SSH_AUTH_SOCK=${SSH_AUTH_SOCK:-/dev/null}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Cache (Composer and Yarn both follows XDG Base Directory Specification. For
6+
# the others, related environment variables must be expanded at runtime)
7+
if [ -n "${XDG_CACHE_HOME}" ]; then
8+
mkdir -p ${XDG_CACHE_HOME}
9+
# Bash
10+
export HISTFILE="${XDG_CACHE_HOME}/.bash_history"
11+
# Ansible
12+
export ANSIBLE_CACHE_PLUGIN_CONNECTION="${XDG_CACHE_HOME}/ansible"
13+
fi
14+
15+
# Ssh authorization socket
16+
if [ -n "${SSH_AUTH_SOCK}" ]; then
17+
sudo chmod 777 ${SSH_AUTH_SOCK}
18+
fi
19+
20+
# Ssh key
21+
if [ -n "${SSH_KEY}" ]; then
22+
eval `ssh-agent` 1>/dev/null
23+
ssh-add ${SSH_KEY} 2>/dev/null
24+
fi
25+
26+
exec "$@"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Host *
2+
StrictHostKeyChecking no
3+
HashKnownHosts no
4+
UserKnownHostsFile /dev/null
5+
LogLevel ERROR

0 commit comments

Comments
 (0)