Use drush-patchfile in DDEV environment - ddev

In Drupal 7 I use
drush-patchfile
to automatically implements patches when installing/updating module via drush. But in DDEV I don't know how to extend existing drush with drush-patchfile
As you can see on https://bitbucket.org/davereid/drush-patchfile section Installation, I need to clone the repository into
~/.drush
directory and that will append it to existing drush.
On another project without DDEV, I've already done that with creating new docker image file
FROM wodby/drupal-php:7.1
USER root
RUN mkdir -p /home/www-data/.drush && chown -R www-data:www-data /home/www-data/;
RUN cd /home/www-data/.drush && git clone https://bitbucket.org/davereid/drush-patchfile.git \
&& echo "<?php \$options['patch-file'] = '/home/www-data/patches/patches.make';" \
> /home/www-data/.drush/drushrc.php;
USER wodby
But I'm not sure how to do that in DDEV container.
Do I need to create a new service based on drud/ddev-webserver or something else?
I've read documentation but not sure in what direction to go.

Based on #rfay comment, here solution that works for me (and with little modification can works for other projects).
I've cloned repo outside of docker container; for example, I've cloned into
$PROJECT_ROOT/docker/drush-patchfile
Create custom drushrc.php in the $PROJECT_ROOT/.esenca/patches folder (you can choose different folder)
<?php
# Location to the patch.make file. This should be location within docker container
$options['patch-file'] = '/var/www/html/.esenca/patches/patches.make';
Add following hooks into $PROJECT_ROOT/.ddev/config.yaml
hooks:
post-start:
# Copy drush-patchfile directory into /home/.drush
- exec: "ln -s -t /home/.drush/ /var/www/html/docker/drush-patchfile"
# Copy custom drushrc file.
- exec: "ln -s -t /home/.drush/ /var/www/html/.esenca/patches/drushrc.php"
Final project structure should looks like
.
├── .ddev
│   ├── config.yaml
│   ├── docker-compose.yaml
│   ├── .gitignore
│   └── import-db
├── docker
│   ├── drush-patchfile
│   │   ├── composer.json
│   │   ├── patchfile.drush.inc
│   │   ├── README.md
│   │   └── src
├── .esenca
│   └── patches
│   ├── drushrc.php
│   └── patches.make
├── public_html
│   ├── authorize.php
│   ├── CHANGELOG.txt
│   ├── COPYRIGHT.txt
│   ├── cron.php
│   ├── includes
│   ├── index.html
│   ├── index.php
│   ├── INSTALL.mysql.txt
│   ├── INSTALL.pgsql.txt
│   ├── install.php
│   ├── INSTALL.sqlite.txt
│   ├── INSTALL.txt
│   ├── LICENSE.txt
│   ├── MAINTAINERS.txt
│   ├── misc
│   ├── modules
│   ├── profiles
│   ├── README.txt
│   ├── robots.txt
│   ├── scripts
│   ├── sites
│   │   ├── all
│   │   ├── default
│   │   ├── example.sites.php
│   │   └── README.txt
│   ├── themes
│   ├── Under-Construction.gif
│   ├── update.php
│   ├── UPGRADE.txt
│   ├── web.config
│   └── xmlrpc.php
└── README.md
At the end start ddev envronment
ddev start
and now you can use drush-patchfile commands within web docker container.

You can ddev ssh and then sudo chown -R $(id -u) ~/.drush/ and then do whwatever you want in that directory (~/.drush is /home/.drush).
When you get it going and you want to do it repetitively for every start, you can encode the instructions you need using post-start hooks: https://ddev.readthedocs.io/en/latest/users/extending-commands/
Please follow up with the exact recipe you use, as it may help others. Thanks!

Related

Copying entire folder structure from a role merging/overwriting with already existing files

I use Ansible to deploy my userspecific configuration (shell, texteditor, etc.) on a newly installed system. That's why i have all config files in my roles file directory, structured the same way as they should be placed in my home directory.
What's the correct way to realize this? I don't want to list every single file in the role and exisiting files should be overwriten, existing directories should be merged.
I've tried the copy module, but the whole task is skipped; I assume because the parent directory(.config) already exist.
Edit: add the requested additional information
Ansible Version: 2.9.9
The roles copy task:
- name: Install user configurations
copy:
src: "home/"
dest: "{{ ansible_env.HOME }}"
The Files to copy in the role directory:
desktop-enviroment
├── defaults
│   └── main.yml
├── files
│   └── home
│   ├── .config
│   │   ├── autostart-scripts
│   │   │   └── ssh-keys.sh
│   │   ├── MusicBrainz
│   │   │   ├── Picard
│   │   │   ├── Picard.conf
│   │   │   └── Picard.ini
│   │   ├── sublime-text-3
│   │   │   ├── Installed Packages
│   │   │   ├── Lib
│   │   │   ├── Local
│   │   │   └── Packages
│   │   └── yakuakerc
│   └── .local
│   └── share
│   ├── plasma
│   └── yakuake
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── tasks
│   ├── desktop-common.yaml
│   ├── desktop-gnome.yaml
│   ├── desktop-kde.yaml
│   └── main.yml
├── templates
└── vars
└── main.yml
The relevant ansible output:
TASK [desktop-enviroment : Install user configurations] **
ok: [localhost]

Correct directory structure for Puppet RSpec testing

I'm having some issues creating unit tests for my Puppet control repository.
I mostly work with roles and profiles with the following directory structure:
[root#puppet]# tree site
site
├── profile
│   ├── files
│   │   └── demo-website
│   │   └── index.html
│   └── manifests
│   ├── base.pp
│   ├── ci_runner.pp
│   ├── docker.pp
│   ├── gitlab.pp
│   ├── logrotate.pp
│   └── website.pp
├── role
│   └── manifests
│   ├── gitlab_server.pp
│   └── nginx_webserver.pp
Where do I need to place my spec files and what are the correct filenames?
I tried placing them here:
[root#puppet]# cat spec/classes/profile_ci_runner_spec.rb
require 'spec_helper'
describe 'profile::ci_runner' do
...
But I get an error:
Could not find class ::profile::ci_runner
The conventional place for a module's spec tests is in the module, with the spec/ directory in the module root. So site/profile/spec/classes/ci_runner_spec.rb, for example.
You could consider installing PDK, which can help you set up the structure and run tests, among other things.

Kubernetes client code generator: Can the code exist only locally and not on a repository for the core-generator to work?

I am trying to generate client code using k8s.io/code-generator.
These are the instructions that I am following: https://itnext.io/how-to-generate-client-codes-for-kubernetes-custom-resource-definitions-crd-b4b9907769ba
My question is, does my go module need to be present on a repository or can I simply run the generate-groups.sh script on a go module that is ONLY present on my local system and not on any repository?
I have already tried running it and from what I understand, there needs to be a repository having ALL the contents of my local go module. Is my understanding correct?
You CAN run kubernetes/code-generator's generate-groups.sh on a go module that is only present on your local system. Neither code-generator nor your module needs to be in your GOPATH.
Verification
Cloned kubernetes/code-generator into a new directory.
$HOME/somedir
├── code-generator
Created a project called myrepo and mocked it with content to resemble sample-controller. Did this in the same directory to keep it simple.
somedir
├── code-generator
└── myorg.com
└── myrepo # mock of sample-controller
├── go.mod
├── go.sum
└── pkg
└── apis
└── myorg
├── register.go
└── v1alpha1
├── doc.go
├── register.go
└── types.go
My go.mod looked like
module myorg.com/myrepo
go 1.14
require k8s.io/apimachinery v0.17.4
Ran generate-group.sh. The -h flag specifies which header file to use. The -o flag specifies the output base which is necessary here because we're not in GOPATH.
$HOME/somedir/code-generator/generate-groups.sh all myorg.com/myrepo/pkg/client myorg.com/myrepo/pkg/apis "myorg:v1alpha1" \
-h $HOME/somedir/code-generator/hack/boilerplate.go.txt \
-o $HOME/somedir
Confirmed code generated in correct locations
myrepo
├── go.mod
├── go.sum
└── pkg
├── apis
│   └── myorg
│   ├── register.go
│   └── v1alpha1
│   ├── doc.go
│   ├── register.go
│   ├── types.go
│   └── zz_generated.deepcopy.go
└── client
├── clientset
│   └── versioned
│   ├── clientset.go
│   ├── doc.go
│   ├── fake
│   ├── scheme
│   └── typed
├── informers
│   └── externalversions
│   ├── factory.go
│   ├── generic.go
│   ├── internalinterfaces
│   └── myorg
└── listers
└── myorg
└── v1alpha1
Sources
Go modules support https://github.com/kubernetes/code-generator/issues/57
Documentation or support for Go modules https://github.com/kubernetes/sample-controller/issues/47

Cant install SPHINX - PermissionError: [Errno 13] Permission denied: './source'

Sphinx Quickstart wont let me go beyond the step where we confirm we need the docs in English .
I have an existing CONDA venv named - demo_venv.
I activate that and do a pip install , directory structure is as seen below -
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx$ pip install sphinx
the directory tree -
pycon-sphinx-tutorial
├── crawler
├── install.sh
├── README.rst
├── tutorial
As can be seen from the - tree , above and the Error below its a PermissionError: [Errno 13].
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs$ sphinx-quickstart
Welcome to the Sphinx 2.2.1 quickstart utility.
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).
Selected root path: .
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: y
The project name will occur in several places in the built documentation.
> Project name: Crawler
> Author name(s): RohitDhankar
> Project release []: 1.0
If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.
For a list of supported codes, see
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language.
> Project language [en]: en
Traceback (most recent call last):
File "/home/dhankar/anaconda2/envs/demo_venv/bin/sphinx-quickstart", line 10, in <module>
sys.exit(main())
File "/home/dhankar/anaconda2/envs/demo_venv/lib/python3.6/site-packages/sphinx/cmd/quickstart.py", line 615, in main
generate(d, overwrite=False, templatedir=args.templatedir)
File "/home/dhankar/anaconda2/envs/demo_venv/lib/python3.6/site-packages/sphinx/cmd/quickstart.py", line 371, in generate
ensuredir(srcdir)
File "/home/dhankar/anaconda2/envs/demo_venv/lib/python3.6/site-packages/sphinx/util/osutil.py", line 79, in ensuredir
os.makedirs(path, exist_ok=True)
File "/home/dhankar/anaconda2/envs/demo_venv/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: './source'
I understand that i need to change my Root path / Root Directory - as of now the SPHINX internal module/file - sphinx/cmd/quickstart.py , is unable to get to the right path where it has the correct permissions to create the _build directory. My QUESTION -- How to solve for this ?
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs$ sphinx-quickstart -c /media/dhankar/Dhankar_1/a5_test_sphinx
usage: sphinx-quickstart [OPTIONS] <PROJECT_DIR>
sphinx-quickstart: error: unrecognized arguments: -c
Am not sure if this is the best or even a correct approach . But for now this is what ive done -
Edited the file - sphinx/cmd/quickstart.py - as seen below , changed the value for the path within the dictionary DEFAULTS.
DEFAULTS = {
#'path': '.',
'path': '/media/dhankar/Dhankar_1/a5_test_sphinx/',
'sep': False,
'dot': '_',
'language': None,
'suffix': '.rst',
'master': 'index',
'makefile': True,
'batchfile': True,
}
This now gave me in terminal -
Welcome to the Sphinx 2.2.1 quickstart utility.
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).
Selected root path: .
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: n
The project name will occur in several places in the built documentation.
> Project name: Crawler
> Author name(s): RohitDhankar
> Project release []: 1.0
If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.
For a list of supported codes, see
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language.
> Project language [en]: en
Creating file ./conf.py.
Creating file ./index.rst.
Creating file ./Makefile.
Creating file ./make.bat.
Finished: An initial directory structure has been created.
You should now populate your master file ./index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
Also the TREE at the directory is as seen below -
dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx$ tree
.
└── pycon-sphinx-tutorial
├── crawler
│   ├── _build
│   ├── conf.py
│   ├── docs
│   ├── index.rst
│   ├── make.bat
│   ├── Makefile
│   ├── src
│   │   ├── crawler
│   │   │   ├── __init__.py
│   │   │   ├── main.py
│   │   │   └── utils.py
│   │   └── __init__.py
│   ├── _static
│   └── _templates
├── install.sh
├── README.rst
├── tutorial
│   ├── cheatsheet.html
│   ├── finish.html
│   ├── genindex.html
│   ├── glossary.html
│   ├── _images
│   │   ├── cheatsheet-back-full.png
│   │   └── cheatsheet-front-full.png
│   ├── index.html
│   ├── objects.inv
│   ├── py-modindex.html
│   ├── search.html
│   ├── searchindex.js
│   ├── _sources
│   │   ├── cheatsheet.txt
│   │   ├── finish.txt
│   │   ├── glossary.txt
│   │   ├── index.txt
│   │   ├── start.txt
│   │   ├── step-1.txt
│   │   ├── step-2.txt
│   │   ├── step-3.txt
│   │   └── useful-links.txt
│   ├── start.html
│   ├── _static
│   │   ├── ajax-loader.gif
│   │   ├── basic.css
│   │   ├── comment-bright.png
│   │   ├── comment-close.png
│   │   ├── comment.png
│   │   ├── css
│   │   │   ├── badge_only.css
│   │   │   ├── badge_only.css.map
│   │   │   ├── theme.css
│   │   │   └── theme.css.map
│   │   ├── doctools.js
│   │   ├── down.png
│   │   ├── down-pressed.png
│   │   ├── file.png
│   │   ├── fonts
│   │   │   ├── FontAwesome.otf
│   │   │   ├── fontawesome-webfont.eot
│   │   │   ├── fontawesome-webfont.svg
│   │   │   ├── fontawesome-webfont.ttf
│   │   │   ├── fontawesome-webfont.woff
│   │   │   ├── Inconsolata-Bold.ttf
│   │   │   ├── Inconsolata-Regular.ttf
│   │   │   ├── Inconsolata.ttf
│   │   │   ├── Lato-Bold.ttf
│   │   │   ├── Lato-Regular.ttf
│   │   │   ├── RobotoSlab-Bold.ttf
│   │   │   └── RobotoSlab-Regular.ttf
│   │   ├── jquery-1.11.1.js
│   │   ├── jquery.js
│   │   ├── js
│   │   │   ├── modernizr.min.js
│   │   │   └── theme.js
│   │   ├── minus.png
│   │   ├── plus.png
│   │   ├── pygments.css
│   │   ├── searchtools.js
│   │   ├── underscore-1.3.1.js
│   │   ├── underscore.js
│   │   ├── up.png
│   │   ├── up-pressed.png
│   │   └── websupport.js
│   ├── step-1.html
│   ├── step-2.html
│   ├── step-3.html
│   └── useful-links.html
└── tutorial-setup.sh
15 directories, 75 files
dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx$
havent done anything else yet - will report back if this works .
EDIT --1-
Further manually altered the directory structure - now the tree is as below --
└── pycon-sphinx-tutorial
├── crawler
│   ├── docs
│   │   ├── _build
│   │   ├── conf.py
│   │   ├── index.rst
│   │   ├── make.bat
│   │   ├── Makefile
│   │   ├── _static
│   │   └── _templates
│   └── src
│   ├── crawler
│   │   ├── __init__.py
│   │   ├── main.py
│   │   └── utils.py
│   └── __init__.py
├── install.sh
├── README.rst
├── tutorial
│   ├── cheatsheet.html
│   ├── finish.html
│   ├── genindex.html
│   ├── glossary.html
│   ├── _images
│   │   ├── cheatsheet-back-full.png
│   │   └── cheatsheet-front-full.png
│   ├── index.html
│   ├── objects.inv
│   ├── py-modindex.html
│   ├── search.html
│   ├── searchindex.js
│   ├── _sources
│   │   ├── cheatsheet.txt
│   │   ├── finish.txt
│   │   ├── glossary.txt
│   │   ├── index.txt
│   │   ├── start.txt
│   │   ├── step-1.txt
│   │   ├── step-2.txt
│   │   ├── step-3.txt
│   │   └── useful-links.txt
│   ├── start.html
│   ├── _static
│   │   ├── ajax-loader.gif
│   │   ├── basic.css
│   │   ├── comment-bright.png
│   │   ├── comment-close.png
│   │   ├── comment.png
│   │   ├── css
│   │   │   ├── badge_only.css
│   │   │   ├── badge_only.css.map
│   │   │   ├── theme.css
│   │   │   └── theme.css.map
│   │   ├── doctools.js
│   │   ├── down.png
│   │   ├── down-pressed.png
│   │   ├── file.png
│   │   ├── fonts
│   │   │   ├── FontAwesome.otf
│   │   │   ├── fontawesome-webfont.eot
│   │   │   ├── fontawesome-webfont.svg
│   │   │   ├── fontawesome-webfont.ttf
│   │   │   ├── fontawesome-webfont.woff
│   │   │   ├── Inconsolata-Bold.ttf
│   │   │   ├── Inconsolata-Regular.ttf
│   │   │   ├── Inconsolata.ttf
│   │   │   ├── Lato-Bold.ttf
│   │   │   ├── Lato-Regular.ttf
│   │   │   ├── RobotoSlab-Bold.ttf
│   │   │   └── RobotoSlab-Regular.ttf
│   │   ├── jquery-1.11.1.js
│   │   ├── jquery.js
│   │   ├── js
│   │   │   ├── modernizr.min.js
│   │   │   └── theme.js
│   │   ├── minus.png
│   │   ├── plus.png
│   │   ├── pygments.css
│   │   ├── searchtools.js
│   │   ├── underscore-1.3.1.js
│   │   ├── underscore.js
│   │   ├── up.png
│   │   ├── up-pressed.png
│   │   └── websupport.js
│   ├── step-1.html
│   ├── step-2.html
│   ├── step-3.html
│   └── useful-links.html
└── tutorial-setup.sh
15 directories, 75 files
EDIT -2 ---
All seems to be fine now --- my initial question remains - How would i have correctly changed the path --- Selected root path: . , in place of the default path ?
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs$ make html
Running Sphinx v2.2.1
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindexdone
writing additional pages... searchdone
copying static files... ... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.
The HTML pages are in _build/html.
Am able to serve the basic page at http://localhost:8000/
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs$ cd _build/
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build$ ls
doctrees html
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build$ cd html
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build/html$ ls
genindex.html index.html objects.inv search.html searchindex.js _sources _static
(demo_venv) dhankar#dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build/html$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/alabaster.css HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/pygments.css HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/documentation_options.js HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/underscore.js HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/custom.css HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/doctools.js HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/language_data.js HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:41] "GET /_static/basic.css HTTP/1.1" 200 -
127.0.0.1 - - [29/Oct/2019 22:31:42] code 404, message File not found
127.0.0.1 - - [29/Oct/2019 22:31:42] "GET /favicon.ico HTTP/1.1" 404 -

How can I recursively go to every folders and execute shell script with the same name?

I have this directory.
.
├── animation
│   ├── animation-events
│   │   ├── app.js
│   │   ├── app.mustache.json
│   │   ├── create_view.sh
│   │   └── assets
│   │   └── dummy_character_sprite.png
│   └── change-frame
│   ├── app.js
│   ├── app.mustache.json
│      ├── create_view.sh
│   └── assets
│   └── dummy_character_sprite.png
├── app.css
├── app.mustache
├── bunch_of_functions.js
├── decorators.js
├── create_all_views.sh
└── displaying-a-static-image
├── app.js
├── app.mustache.json
├── create_view.sh
└── assets
└── piplup.png
I want for create_all_views.sh to execute all create_view.sh in the children directory. How can I achieve such thing?
As you are in Ubuntu, you have the GNU implementation of find,
which has the -execdir option,
and you can do like this:
find path/to/dir -name create_view.sh -execdir ./create_view.sh \;
That is,
for each create_view.sh file it finds in the directory tree,
it will execute ./create_view.sh in the directory of that file.

Resources