How can you reference a submodule in openshift - node.js

I've got an account with OpenShift which provides a git repository for each project you to work in. I've got one main project and two smaller projects resulting in a total of 3 git repositories.
I have just started to use the two smaller projects in the main project and seen that git can use the submodule command. I've added them both to the custom directory like so:
git submodule add ssh://...#app.rhcloud.com/~/git/app.git/
git submodule add ssh://...#api.rhcloud.com/~/git/api.git/
which has produced a directory structure like so:
node_modules
custom
app ------ full of tasty files
api ------ full of tasty files
index.js
.gitmodules
Within the .gitmodules file I have
[submodule "custom/api"]
path = custom/api
url = ssh://...#api.rhcloud.com/~/git/api.git/
[submodule "custom/app"]
path = custom/app
url = ssh://...#app.rhcloud.com/~/git/app.git/
Which is exactly what I want. It all works locally.
git add --all
git commit -m "new submodules"
git push
The issue is when I run the git push, it comes back with this error:
remote: Host key verification failed.
remote: fatal: Could not read from remote repository.
remote:
remote: Please make sure you have the correct access rights
remote: and the repository exists.
It looks like I need to add the ssh key of the main project to the two smaller projects so that I can ssh. Does anyone know how I can do this or have a better way of including submodules in OpenShift?
Thanks for the help in advance.

It looks like I need to add the ssh key of the main project to the two smaller projects so that I can ssh
At the parent (main) repo level, this shouldn't be the case: all the push does is to push the .gitmodules, and 2 gitlinks (special entries in the index) representing those 2 submodules.
It is more likely that the push doesn't find the proper .ssh/known_hosts, or the public/private ssh keys in order to push back to the app.rhcloud.com upstream repo: See "SSH connection problem with “Host key verification failed…” error" and "The authenticity of host can't be established".

Related

Pushing a respository I initialised with git init inside another repository to github

I am currently doing course called fullstackopen for which I created a repository on Github called fso and cloned it locally using ssh. Inside fso, I created directories for different parts(part1, part2) and created react projects inside them (using create-react-app). I pushed them to github without any problems.
For part3, the course asked to create a new repository for the backend(node js). I created this repo inside fso/part3 using git init and initialised a node app called phonebook. Now, when I tried to push it to Github, I got this:
enter image description here
So, I added my github repo using:
git remote add origin
After this when I tried to push again, I was prompted for my username and password but support for password authentication has been removed. I tried pushing using personal access tokens and got this:
enter image description here
Can I run the following in my part3/phonebook (phonbook-backend) directory?
git pull origin master git push origin master
I'm not sure if this would work, I dont want to lose my work.
Edit: i tried git pull origin main --allow-unrelated-histories and got this
pushing after this results in the same error
this is what my directory structure looks like locally. Im trying to push part3 to my github repo
Your last error is 'updates were rejected because the remote contains work'
This happens when your repository gets initialized with additional files like README or GITIGNORE. To resolve this, first you need to pull your changes from server, so you can use below command:
'git pull origin main --allow-unrelated-histories'
Then you can push your changes to server using below command:
'git push -f origin main'

GitLab runner unable to clone private GitLab repositories

I'm using a shared runner that has access to the entire project group. In this one particular project on my GitLab server whose visibility is set to "private", when the runner attempts to clone the repository, it presents an error message noting that it could not clone the repository with a 403 response.
I searched high and low in the documentation but couldn't find the explanation for this nor a solution to this problem. I noticed when I switched the project's visibility to internal, everything started working.
Does anyone know why GitLab runners cannot access private repositories? If I wish to grant the runner access and the ability to execute the repo's CICD pipeline, how can I do so?
Here are the logs:
Fetching changes with git depth set to 50...
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /builds/4q6GE3ka/0/mysecretproject/myproject/.git/
Created fresh repository.
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://example.com/mysecretproject/project.git/': The requested URL returned error: 403

How to push both the client side and server side project folders together as a one project (api + front end) on github?

I have completed my project.
My stack :
Front-End UI => Reactjs
Back-End => Nodejs/Expressjs + MongoDB
And below is my project structure containing both the folders:
project_Name > client + server
project_Name is the main folder
client and server are the separate folders both are inside project_Name folder.
And inside client and server folder I have installed the respective npm modules (reactjs + nodejs)
My API end point is running on localhost:8000
and reactjs on localhost:5000
So now I want to add my project to github repository.
I am confused how to achieve that?
Do I need to push both client and server side code on separate 2 different gits?
Or
I need to upload just project_Name folder containing both side project files?
But is it so then how can I do that?
Since before pushing to git, the directory should have the package.json file and node_modules which will be only inside the client and server side folders.
These are the git commands to push the project I am using:
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/vik.........git
git push -u origin main
But I don't know in which folder I have to initiate the repository first?
Let me know the solution please .
Thanks!
If your project that you created has it's own folder then what you would need to do is:
Root Folder: Project
./client
./server
Initiate .git from your ROOT FOLDER.
git add . (which then adds all the files)
git commit... And so on. Feel free to comment if you need any help!
It'll add all your files in one go, so don't worry so much and it won't push any empty folders.
There's some instances where create-react-app, will create a git repo on it's own.
On your file explorer look for the hidden files, and be sure to delete that .git folder in your client before pushing your stuff, it'll throw you an error.
run NPM install on your main folder, it'll create a package.json for you.
Try not to think about it so hard and take it slow.
Hopes this helps!
I think you should use this structure:
-projectName: folder
- frontend: folder
- package.json
- backend: folder
- package.json
- package.json
For executing the app you can use github actions:
https://docs.github.com/en/free-pro-team#latest/actions
https://github.com/features/actions
OR
You can also use services like heroku or firebase, see my project (it is just a simple project for resolving this problem you are asking for)
https://github.com/simCecca/InformationVisualizationWorldWide
The structure is:
-projectName: folder
- frontend: folder
- package.json
backend code
package.json // containing the BE dependencies and the dependencies for the
deploy in heroku in this case
https://dashboard.heroku.com/
I hope I responded to your question, if I'have not, please reply to this response
I solved this problem by adding the .gitignore file in the root folder (in same level as client and server) and inside that this line: node_modules/
this will ignore node_modules of both client and server.
after that initialize git:
Git init
git add .
git commit -m 'commit message'
git push -u origin master
Now you can visit GitHub repositories and confirm there isn't node_modules folder anymore
Delete the node_modules and push it from the root.
just copy and paste the .gitignore file in both frontend and backend folder, git will not upload node_modules folder in git repository.
After creating two folders named client and backend in a root folder(suppose the name is: my-project). Now we would like to push our code to remote like this.
a) create a repo named my-project in GitHub(same name as the root folder)
b)checking in the terminal of my local to check if it is in the root or not.
c)from root: my-project % run all the following commands.
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/vik.........git
git push -u origin main
d) now from the root in each folder[client and backend] create a .gitignore file and write node_modules to ignore node_modules if needed.
e)git add .
f)git commit -m 'all codes is pushed to remote'
g)git push origin main
Now all codes are in the remote.
If any code is changed for example in the client.
a) cd client
b) git status
c9 git add ./ file name
d) git commit -m 'client code is pushed'
e) git push origin main
client code is now updated in remote too.
Hope it would help.

GitLab pull submodules inside CI

I have a GitLab project that utilises GitLab CI.
The project also uses submodules, both the project and it's submodules are under the same GitLab account.
Here is my .gitmodules file
[submodule "proto_contracts"]
path = proto_contracts
url = https://gitlab.com/areller/proto_contracts.git
I also have this piece in the .gitlab-ci.yml file
variables:
GIT_SUBMODULE_STRATEGY: recursive
However, when i run the CI I get this error
fatal: could not read Username for 'https://gitlab.com': No such device or address
Both the project and the submodules are in a private repository so you would expect to be prompted for authentication, but as I've mentioned, the project and the submodule are under the same account and one of the runner's jobs is to clone the original repository
So it's odd that it's unable to reach the submodule
Is there a way around it?
You must use relative URLs for submodules. Update your .gitmodules as follow:
[submodule "proto_contracts"]
path = proto_contracts
url = ../../areller/proto_contracts.git
Further reading: Using Git submodules with GitLab CI | GitLab Docs

Git - Automatic pulling in server

I'm desperately trying to prepare a correct environment for a new project. We plan to work locally with Xampp with my team and then push everything on a testing server, so I've started to learn git and its specificities.
When I try to push everything is ok, but then I want my server to automatically pull the updated files where it was cloned. So I created a post-update file which is like this.
#!/bin/bash
echo "Mise en production..."
cd /home/test/public_html/
unset GET_DIR
git fetch origin master
The problem is I get this error
remote: Mise en production...
remote: fatal: Not a git repository: '.'
Is there a better solution that would be efficient ?
Thanks everyone.
Your attempted solution works, but you have overlooked one detail.
When changing into /home/test/public_html/, you need to realize that this directory is not a Git repository and hence, you cannot fetch into it. To make this work, execute the following once.
$ cd /home/test/public_html
$ git init
$ git remote add origin [path/to/git/repo]
After that, you'll be able to git fetch and git pull in /home/test/public_html.
The [path/to/git/repo] should be a relative or absolute path to the directory that contains your repository. This is the directory that has directories branches, hooks, info, et cetera.
It seems you need that after the local repo changes are pushed to a testing server, then you also want the local changes are pushed to your server. So you can use post-update hook to do that:
In the testing server, edit the contents of hooks/post-update file as below:
#!/bin/sh
echo "Mise en production..."
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
git push -u /path/for/your/server $branch
echo "push to my server "

Resources