Including a subfolder from an excluded folder in .gcloudignore - gcloud

I'm trying to deploy a Node project with a Dockerfile to Google Cloud Run with the gcloud beta run deploy command.
Long story short, I would like to copy my local node_modules/my-module after running RUN npm install in the Dockerfile:
COPY node_modules/my-module /app/node_modules/my-module/
(I only do this while in development, to avoid committing and pushing every change from my-module for testing).
Unfortunately, Docker cannot copy this directory since, apparently, node_modules is not uploaded to Cloud Build by default.
So I created this .gcloudignore file to override the default:
.gcloudignore
.git
.gitignore
node_modules/
!node_modules/my-module/
I've tried a lot of other syntaxes but none allowed me to exclude node_modules while including node_modules/my-module.
However, I can include the whole node_modules directory by omitting it from the .gcloudignore file, but this obviously takes forever to upload.
Do you know how I could upload my local module to Cloud Build?

After reading this Gist's comments, I realized you have to also include the parent directories, like so:
node_modules/**
!node_modules/
!node_modules/my-module/**
This will exclude all subfolders from node_modules except my-module and its content (the ** is important, otherwise only the empty folder would be included).

Related

cypress upload to github does node_modules needed?

does "node_modules" folder required when I upload the cypress folders to github?
i am very new to this and wonder if my teammate can run the test at his machine without downloading the "node_modules".
You can create a file called .gitignore and mention node_modules there. Then when you are uploading your project to GitHub, everything that is mentioned in .gitignore would be ignored for upload. It is not advised to upload the node_modules folder to git. This is how my gitignore looks like for my project:
Now if your teammate wants to execute the test, they can just run the command npm install. It will install download all the dependencies from the package.json file and will automatically create a node_modules folder in their machine.

.gitignore not ignoring a folder within a directory

It seems a straightforward one, but having researched multiple ways to do it, I can't gitignore a folder within a directory.
I have a root directory which contains all of my code in it. Because it has some back-end NodeJS stuff in it, it has a 'node_modules' folder which contains hundreds of files. As a result, when I try to upload the entire parent folder, GitHub says there's too many files to upload and tells me to reduce the number I'm uploading.
The crucial part is though, the folder has to be uploaded as a whole, as it itself is within a GitHub repository with other files with different folders in.
That means when I go onto my repository, I need this folder's files to display within the folder, and not separately within the repository. I need all of the files to be within this folder, within the parent repository, excluding the node_modules folder.
For example ->
Parent repository -> Child Directory (what I'm uploading) -> Individual files
I've tried to add the node_modules folder to my gitignore through the following methods:
Adding: node_modules/ to my gitignore file
Writing: echo node_modules >> .gitignore through my terminal
Adding a separate gitignore file within my node_modules file with a * in it
None of them have worked and I can't find any other solutions. For reference I'm using a Mac.
Does anyone have any idea what I'm doing wrong, or how it'd be best to do it?
By default, you do not need to include the node_modules folder in your repositories because the package.json file contains all of your project's dependency information. This means that anyone who clones your repository can run npm install and have the entire node_modules folder without problems.
To solve this you can create your own .gitignore file, creating a new file at the root of your project and renaming it to .gitignore (writing exactly that way). Then you can open it with any text editor and add */node_modules to one of the lines.
This will likely solve your problem.

How to download git ignored folders and files from github

Am trying to download node_modules from github inorder to install it in an offline machine,
What i did was just froked a repository and deleted the .gitignore file and tried downoad the zip file again,but still not getting node modules
Is it possible to download ignored folders from github?
No. The node_modules folder, as it is ignored, is not even saved in git. There's nothing you can do to download it with the rest of the repository, just run npm install or yarn. As the machine in question isn't connected, you'll naturally have to do this on an internet-connected machine.

Files from Yeoman web-app that needs to be committed in SCM/GIT

When we do "yo webapp" (assuming webapp generator is installed), it scaffold projects which contains file relevant to bower, grunt and then there is app folder, which we all know what's it about.
My question is, out of this structure what are the files that needs to be maintained in SCM, Should it be only app directory or should it whole structure ?(assuming there are no additional grunt task or any build file changes from earlier scaffolding)
Yeoman webapp generator will produce a .gitignore file which includes files that should not be committed to a SCM. This file includes the following directories:
node_modules
dist
.tmp
.sass-cache
bower_components
test/bower_components
It is clear that .tmp and .sass-cache have no reason to be in the repo as they both are only temporary.
There is however a discussion whether bower (and rarely node) dependencies should be checked in. For most projects I recommend not to.
Please note that in either case one should never change the packages directly in the bower_components or node_modules folder as any change will be lost at next bower install or npm install. A fork of the original project (either as a independent repo or to folder in the project - e.g. lib) is a better idea - a follow up pull request would then add a lot of karma :)
The dist folder with the build of the application may be committed depending on your deployment method. There is a very good guide on deployment on Yeoman site.
As a start, you should put everything into SCM with the exception of app/bower_components, test/bower_components and node_modules. All files under these directories come from public repo, either node or bower repo.
In this setup, whenever another developer checkout from SCM, he needs to run 2 commands: npm install and bower install. What I typically do is I create a file called install.sh (install.bat on Windows) and have these 2 commands inside this script file. In this way, when you find that you need to run more commands for initialization, you can easily add to this script file and new developers can just checkout and run install.sh.
In some cases, I found that I need to perform small modification to a public library. In this case, I will check this library inside bower_components into SCM as well. This is not common, but it happens.

Is there a way to control what gets into a GitHubs zipball?

Every GitHub repo has the Download ZIP button, but is there a way to control what gets into the final zipball. For example we do not need and hidden files there, or even - unit tests.
Excerpt from Pro Git book:
You can tell Git not to export certain files or directories when
generating an archive. If there is a subdirectory or file that you
don’t want to include in your archive file but that you do want
checked into your project, you can determine those files via the
export-ignore attribute.
For example, say you have some test files in a test/ subdirectory, and
it doesn’t make sense to include them in the tarball export of your
project. You can add the following line to your Git attributes file:
test/ export-ignore
Now, when you run git archive to create a tarball of your project,
that directory won’t be included in the archive.