Post-receive githook to push database to live site - database

I'm busy workflow with Git. What I want to achieve is pushing a local repository with the database to Bitbucket and then automatically push the files to a server and put the mysqldump file into the database.
I can now make a mysqldump of the database with the git pre-commit hook and push this to my Bitbucket repo. After that I want to handle database import automaticcaly.
I found out that this is possible with the post-receive hook, but can't get it working. Where do I have to add that hook? I tried it in the local git hooks folder where my pre-commit hook is located, but it does nothing.
Anyone who can help me?

You can use a post-commit Webhook from Bitbucket (see documentation).
To handle the Webhook, you'll need a server that receives it, then pull the changes and executes whatever you want (your database import).
I made a small node app that receives these hooks if you're interested in re-using it: node-cd

Related

Restrict a file to being edited in gitlab (.gitlab-ci.yml)

as you know We have a file for gitlab ci configuration named '.gitlab-ci.yml'
and this file shouldn't be edited by any developers so I decided to avoid developers to edit it.
the thing is gitlab said you can lock file to being edited but the prerequirement of this action is to have a premium account.
what can I do when I haven't premium account?
do you have any idea to lock a file to being edited?
Check if you have access to a Push Rule feature, which is a kind of pre-receive hook.
Or you can set a pre-receive hook if your GitLab server is on-premise.
In both cases, you can list the files being pushed in that hook, and fails if one of them is .gitlab-ci.yml.
As of today, the official way (~workaround~) for this seems to be creating a different repository for the .yml file with more restrict permissions and then referencing that .yml file from your project:
A .gitlab-ci.yml may contain rules to deploy an application to the production server. This deployment usually runs automatically after pushing a merge request. To prevent developers from changing the .gitlab-ci.yml, you can define it in a different repository. The configuration can reference a file in another project with a completely different set of permissions (similar to separating a project for deployments). In this scenario, the .gitlab-ci.yml is publicly accessible, but can only be edited by users with appropriate permissions in the other project.
https://docs.gitlab.com/ee/ci/environments/deployment_safety.html#protect-gitlab-ciyml-from-change
Also, there is a discussion on this matter here:
https://gitlab.com/gitlab-org/gitlab/-/issues/15632

Bitbucket custom pre-receive hook for preventing unknown users to commit

Currently due to collaboration across different vendors and contractors sometimes they use a malformed git config at the client side when checking in code
Once the code is checked in, bitbucket does not reconcile the correct username against the commit often appearing as in bitbuckets commit section.
This is not desirable for audits and can potentially corrupt the commit trail
Need a custom pre commit hook to call the rest API to verfiy that the user has a account and email address against that REST Endpoint.
Using this tool https://github.com/lovato/hooks4git you can create that script in your preferred language. This tool helps you out with the hook management.
What everyone needs to do (in any client side git hook approach) in to install that tool and activate it.
Other options: https://githooks.com/

Create json server in github.io

I made an angularJS application and it runs form github.io. But I need to use REST API to handle data. I use json-server at my localhost. Is it possible to create and use json-server in github?
I know its old question but I'll still post an answer here just in case someone else wants it.
It is possible to have json-server running in Github pages. Here is the link [https://my-json-server.typicode.com/][1]
Basically create a db.json file in your repository just like you do in the local system. you can access your api with https://my-json-server.typicode.com// as your your root URL.
No, it is not possible because github.io only delivers static files and doesn't run any server.
You will need to use another hosting provider to run the json-server.
See also this question

Git - fetch changes made to files on remote

I would like first to thank you ! Everytime I get stuck I always find a solution here. So thanks a lot !
But this time I need to ask a question : I am currently building a small website with a web interface where admin can change text saved in the sqlite database. I use git locally and to deploy to the server, and a post-receive hook in the bare repo on the server to checkout files in another directory. This dir is then used by nginx and gunicorn to serve the flask app and the files.
Everything works fine for the moment but I had a question : as the database is stored in a file (sqlite) in another directory than the repo, how can I fetch the changes made on the remote file to my local development repo ? Also the user can upload pictures that are rendered on the website, but how can I fetch them to my local repo. Should I init a repo in the directory I could then fetch ? Or is there another solution ?
I know this question may be silly but I am beginning with databases and web interfaces. Thank you in advance for any help !
As I understand, you have the following setup:
local repo L is pushed to remote R
post-receive on remote clones R to U, which is served by HTTP server
user updates U with new content
you'd like to pull changes from remote U to local L
I'm assuming that U is a clone of R. You can just fetch changes from U to your local L - no problem here, as all commits made by the user have the same parent commit as you have in your local L. The only troublesome part is to commit changes made by the user in U. You'll probably need to do some scripting there, so if the user uploads some content - say, via ftp - git commit is fired. Repository U must be accessible somehow - ssh seems to be a good idea in this setup.

Can a server determine the git version of the user client/agent

Can I use git hook to determine the version of the client/agent pushing?
I want to deny a push and send a message when the user/client is too old (or too new).
Not on the server side, as that information (git version) isn't part of what is being pushed.
You could ask the client to have a pre-push hook with your test in it, but there is no guarantee that this hook would be deployed (or bypassed by the user).

Resources