aws-cdk: Any good guides or suggestions for folder structure for web applications? - ruby-on-rails

context: I mostly do rails development along with webpacker. Webpacker puts a package.json at the root of the project.
I was wondering what suggestions people might have for adding aws-cdk into a basic rails application (or any type of web application framework) to make a nice deployment pipeline?
This I've thought about for directory structure:
Adding a .infrastructure folder to the root of the project. This is where all my cdk code would reside. What I don't like about this is during the deploy pipeline I would need to cd into that directoy and run yarn install. Also wouldn't like how I'd have to prefix all my paths with ../ if I need to reference resources outside of the directory (e.g. Dockerfile)
Moving cdk.json to the root of my project. This would solve the path prefix problem but I'd still need todo something along these lines cd .infrastructure && yarn install && cd .. && cdk deploy
Use something like lerna or yarn workspaces? Not sure how much I'd need to configure to webpacker to with those tools.
I tend to over think things way too much...
Am I over complicating this or is a "fullstack engineer" really hard work sometimes? 😅

If you are interested in combining your Infrastructure as Code with your application's deployment strategy you should look into cdk-pipelines. This way, you would just run cdk deploy and all of the build commands would be seperate from the deployment and run as part of the CI/CD build project. I work in .NET but this is how I've structured the folders:
my-repo
my-cool-project
src
MyApi
MyWebApp
cdk
cdk.json
...
Dockerfiles live in 'MyApi', and 'MyWebApp'.

Related

Install dependencies in container using deps.edn

I inherited a clojure code base and I'm trying to containerize it for local development. The creators used deps.edn to manage the dependencies. However, I can't figure out what RUN command I should use to pre-install the dependencies for the project.
Currently, my entrypoint is the following ['clj', '-m', 'app'] which installs the dependencies every time I start the container.
How do I pre-install dependencies for a clojure project using a Docker RUN command?
Deps/CLI caching is described here. Generally speaking, dependencies are downloaded once and saved in a subdirectory of the project directory named
./.cpcache # "class path cache"
The ./.cpcache directory is analagous to the ~/.m2 cache directory used by Maven and related tools (e.g. Leiningen).
If you run the code locally, you should be able to copy the .cpcache dir with its cached dependencies into your Docker container. Then the dependencies don't need to be re-downloaded
for each startup of the Docker container.
See also the Deps/CLI overview.
P.S.
This template project is set up to run using both lein and Deps/CLI via the Kaocha tool. You may find the comparison helpful.
P.P.S.
You may find it easiest to run your code by building an uberjar file which contains all your code and all
dependencies in a single artifact. You can do this either using Leiningen or other tools such as depstar. You then invoke the application with a single command like:
java -jar demo-0.1.0-standalone.jar
Running this should do it:
clj -P

Is it possible to avoid updating drupal core with composer update?

I'm trying to build a docker container where the dockerfile installs a specific version of drupal, I copy over custom copies of composer.json/composer.lock and then do a composer update to download the contributed modules specified in these composer files. I know that ideally composer would also control core, but for this project, I'm trying to avoid that.
The problem I'm having is that composer update seems to also reinstall drupal, where I want the dockerfile to be in control of this and I'd like composer to just manage the modules.
Is this something I could do by modifying the composer files (so far tests have not worked)? It seems you can't specify a package for composer to ignore and where I see you can specify specific packages to update, that's not really a viable solution for this.
Thanks
OK, it's looking like the issue was the composer.lock/json files I was adding to run composer update were initially created by using composer create-project drupal-composer/drupal-project, which installed core and thus added it to the composer.lock/json files.
It seems that by just reinstalling the contributed modules with composer in a fresh drupal site (so simplified composer files) might be the answer.

How to install waf?

I have cloned and built the waf script using:
./waf-light configure
Then to build my project (provided by Gomspace) I need to add waf and the eclipse.py to my path. So far I haven't found better than this setenv script:
WAFROOT=~/git/waf/
export PYTHONPATH=$WAFROOT/waflib/extras/:$PYTHONPATH
export PATH=~/git/waf/:$PATH
Called with:
source setenv
This is somehow a pretty ugly solution. Is there a more elegant way to install waf?
You don't install waf. The command you found correctly builds waf: /waf-light configure build Then for each project you create, you put the built waf script into that projects root directory. I can't find a reference, but this is the way in which waf:s primary author Thomas Nagy wants the tool to be used. Projects that repackage waf to make the tool installable aren't "officially sanctioned."
There are advantages and disadvantages with non-installation:
Disadvantages:
You have to add the semi-binary 100kb large waf file to your repository.
Because the file contains binary code, people can have legal objections to distributing it.
Advantages:
It doesn't matter if new versions of waf break the old API.
Users don't need to install waf before compiling the project -- having Python on the system is enough.
Fedora (at least Fedora 22) has a yum package for waf, so you could see that it's possible to do a system install of waf, albeit with a hack.
After you run something like python3 ./waf-light configure build, you'll get a file called waf that's actually a Python script with some binary data at the end. If you put it into /usr/bin and run it as non-root, you'll get an error because it fails to create a directory in /usr/bin. If you run it as root, you'll get the new directory and /usr/bin/waf runs normally.
Here's the trick that I learned from examining the find_lib() function in the waf Python script.
Copy the waf to /usr/bin/waf
As root, run /usr/bin/waf. Notice that it creates a directory. You'll see something like /usr/bin/.waf-2.0.19-b2f63c807a4215294bf6005410c74c18
mv that directory to /usr/lib, dropping the . in the directory name, e.g. mv /usr/bin/.waf-2.0.19-b2f63c807a4215294bf6005410c74c18 /usr/lib/waf-2.0.19-b2f63c807a4215294bf6005410c74c18
If you want to use waf with Python3, repeat Steps 2-3 running the Python script /usr/bin/waf under Python3. Under Python3, the directory names will start with .waf3-/waf3- instead instead of .waf-/waf-.
(Optional) Remove the binary data at the end of /usr/bin/waf.
Now, non-root should be able to just use /usr/bin/waf.
That said, here's something to consider, like what another answer said: I believe waf's author intended waf to be embedded in projects so that each project can use its own version of waf without fear that a project will fail to build when there are newer versions of waf. Thus, the one-global-version use case seems to be not officially supported.

Getting started with Laradock on Mac

I'm just getting started with learning Laravel, as well as taking my first dive into Docker. I've taken the time to understand what Docker is and (more or less) how it works, and have also set up Docker Native on my Mac (Sierra).
I'm following along with the documentation at: http://laradock.io/getting-started/, but am a bit confused on how to proceed. The current version of Laradock is v5 which has a different setup to previous versions. I'd like to maintain a different docker environment for each project, and as per the documentation:
Follow these steps if you want a separate Docker environment for each project
So I proceeded with the section titled A.2) Don’t have a PHP project yet, where it mentions that the folder should look like:
+ laradock
+ project-z
So in my home directory I have a general Dev folder, and inside that I have a Laravel folder. So in ~/Dev/Laravel/ do I clone the Laradock git repo, and then alongside it (it being the laradock folder that is created) create my projects? So by my understanding I will therefore end up with:
~/Dev/Laravel/laradock
~/Dev/Laravel/project-1
~/Dev/Laravel/project-2
~/Dev/Laravel/project-...
If so, then this does not seem to be a separate Docker environment for each project.
Or should I instead go the route of creating a new empty Laravel project first and then clone the Laradock git repo into that?
I know this a very noobie question, but I'm unsure on how to proceed. Any help is humbly welcome!
Note: I have homebrew, composer and PHP7 already installed on my Mac.
If you want a separate Docker environment for each project, clone the Laradock repo inside each project directory. Your directory structure should look like:
+ project-a
+ laradock-a
+ project-b
+ laradock-b
Alternatively, if you want a single Docker environment for all your projects, your directory structure should look like:
+ laradock
+ project-1
+ project-2
I'd recommend to go with adding laradock as a submodule to an existing laravel app's folder with command: git submodule add https://github.com/Laradock/laradock.git first.
You have to initialize Git first ofc to do that.
To be concrete, you need to see a folder structure like this:

Brunch / Bower testing

When looking at bower.json, I assume putting things in devDependencies is the recommended way to deal with things such unit testing dependencies. I'd like to use qunit as my testing framework, but I guess it should apply to other frameworks as well.
The problem I have is that when I put qunit in devDependencies, it doesn't get picked up when building vendor.js. That's expected, but then how do I go with asking brunch to include it? Obviously, I'd prefer to have test-vendor.js where I'd have dependencies + devDependencies, while keeping devDependencies out of vendor.js.
I have this in config.coffee:
exports.config =
# See http://brunch.readthedocs.org/en/latest/config.html for documentation.
files:
javascripts:
joinTo:
'javascripts/app.js': /^app/
'javascripts/vendor.js': /^(bower_components|vendor)/
'test/javascripts/test.js': /^test\/(?!vendor)/
'test/javascripts/test-vendor.js': /^test\/(?=vendor)/
Obviously, the last line wouldn't pick up any bower_component items as-is. Any suggestions here?
I saw this ticket:
https://github.com/paulmillr/read-components/pull/7
but it looks it's still up in the air.
This SOq:
Is it possible to split production and development Bower components?
suggests there's no way to do it from bower side at the moment.
Until this is implemented natively in Brunch, you can hack around it like this, so long as you aren't using Windows:
Add quint and other test dependencies to devDependencies in bower.json. They will now be managed under bower_components.
Add a symlink for each test dependency from your test/ directory to the relevant file under bower_components, eg:
ln -s ../bower_components/qunit/qunit.js test/
The dependencies will then be included in your unit-tests.js.
When brunch supports devDependencies, you can delete the symlinks.
See Ignore directories in brunch production build
You should be able to do something like:
overrides:
production:
conventions:
ignored: /[\/\\]_|bower_components[\/\\]qunit/
And then generate your production build with brunch b -P (brunch build --production)

Resources