I am writing a service with node.js, and depending on whether a file in my gitlab project has been recently updated or not, the way the service works will change. So how can I tell if the content of a file in my gitlab project has changed or not on the node.js service side? Is there a Gitlab API service for this?
Gitlab does offer a robust API but could you not just run a git fetch and diff:
git fetch origin master
git diff origin/master:./ --compact-summary
That will list any files that have changed compared to your local. If you'd like to access that from Node you could put it in a shell script, run it as a spawned child_process and parse the stdout.
This method depends on your service checking for changes manually, if instead you want your service to be alerted when a change happens at any time you may want to look into webhooks: https://docs.gitlab.com/ee/user/project/integrations/webhooks.html
you can monitor (with a crontab) the project's commits or with webhooks (like #Dave said) and after that get commit diff info with gitlab commit api to see if your file was modified
Related
I'm trying to send a request in my getStaticProps function to my backend api from another docker container. However, even though the api url is written correctly, the static page still is not created. This is because for the static page to be built, the backend should be up already, and because it is build-time the other container is not up yet and waits for the build to be finished and the build can not be finished without the backend.
So what's the solution to this approach? I tried setting the depends_on value to my other container, still doesn't work. what solution would you suggest?
There are 2 solutions I can think of.
Apparently, the Next.js build fails because the service it is querying is not running. Thus why not build and start the service it depends on explicitly and build the rest like this.
docker-compose build some_services
docker-compose up -d some_services
docker-compose build the_rest
This way the Next.js app will be able to make the request. Please keep in mind that You still need to configure the ports and networks correctly. Pretty sure this will resolve the issue.
A more 'fancy' solution would be using build-time networks which are added in the later versions, 3.4+ if I am not mistaken.
docker-compose.yml
build:
context: ./service_directory
network: some_network
For more details please see Docker-compose network
Running a new service that depends whether another service is up or not is a tricky part of docker orchestration. Keep in mind that even with Healthcheck, it doesn't guarantee you database is ready before the next stage. depends_on is not going to be really helpful, because it just determine the order of running service. docker documentation:
depends_on does not wait for db and redis to be “ready” before starting web - only until they have been started. What docker doc suggests is to write a wait-for-it script or [wait-for][2] and run it after or before depends-on. For example:
build: next_service
command: sh -c './wait-for db:5432 -- npm start'
depends_on:
- db
And of course, you explicitly run separate docker-compose command but that loses the point of docker orchestration.
I recently deployed my GitHub project in aws using Amazon Linux 2 AMI.
I installed npm, MongoDB, node and cloned the Github repo into the new instance that I created by sshing into it.
I am running the server with the forever package of npm.
Now, I made some changes in the code and pushed it to my Github repo but it's not being reflected in my project when I try to access it from outside.
So, how to redeploy it so that I see my changes when I access it from outside world?
I found this video which shows how to redeploy but it's not feasible in my case to do it.
Now, I made some changes in the code and pushed it to my Github repo but it's not being reflected in my project
Pushing to GitHub is one step.
But you still need to ssh to your execution environment (aws), and pull from GitHub in order to get the latest.
Then your npm application would have a chance to display your changes.
As an alternative to forever restart, you also can use PM2, as recommended here.
Another option would be to add a GitHub Action, like one of the deployment actions, in order to automate that step.
AWS proposes dedicated GitHub actions.
Full example: "Github Actions for web apps" from Luke Boyle.
From what I'm able to figure out you need to do the following steps:
Do a git pull after logging into your server via ssh.
cd toTheFolder where your git repo is located
git pull origin yourBranchName
forever restart or forever restartall should restart your server and your changes should reflect there.
And as VonC suggested you should go for PM2 instead but for now you can continue with forever. PM2 is very similar to forever but with a lot more features available.
I am reasonably new to angular (5), and have noticed that the javascript files (vendor.bundle, main.bundle, etc) are being reloaded each time I visit a page.
Is there anything in particular I should be doing to make sure that these are held in a browser cache after the first time they are loaded?
I guess I would need to add a cache-control header, but am not sure where to put it in the code, or whether this is something that the Angular-Cli could generate
Angular have lib called Service workers, which simply can be installed in cli project by below cli command
ng add #angular/pwa --project *project-name*
Note: project name can be obtained from angular.json
This command do the most required configuration but still some other stuff is needed, Which can be found on the flowing link service-worker confi. but some of this configuration already done by previous mentioned command. but also more configuration may be needed in "ngsw-config.json" file.
But unfortunately i tested this inside spring war and still the big files still downloaded every time without any caching but if i deployed on http server direct it work perfect.
Inside Spring War Result
For More Info. Please Check the blob of Angular Service Worker - Step-By-Step Guide for turning your Application into a PWA
I'm learning Node and Git and I have a Heroku app that is reading and writing to a local file on the server (a very simple JSON database).
If I add the file to my gitignore locally, it disappears from my Heroku app and causes the app to error. But if I don't add it to my gitignore, it overwrites the latest version (on the server) with an old one I have locally.
Obviously the issue is because the changes on the server file aren't being committed. However, I don't know how to do that remotely, or if it's even possible. I can run heroku git:clone locally, but I can't run heroku:git add.
How do I handle this?
Generally, you should not commit a file that will be modified by the server.
It seems not a good idea because, as you said, this file will be overwrited by next push.
Usually you do not want to commit from your deployment branch, so it is not a good idea either to use git from server (and I doubt you can with Heroku).
Instead you could make your app check if the file exists and if not create that file on server.
That will work in a dedicated server you manage yourself, but Heroku doesn't work the same. Each push you make to your Heroku repository will in fact bundle your application before launching it on a dyno, and this process overwrite all the file, including your database JSON file, which will be no more persistent.
So I think you have no choice than switch to another storage method, for exemple subscribe a free Heroku postgreSQL plan or another database you prefer.
Is there a way so that whenever a pull request is created on github, a new pull request is automatically created after running some npm command (ex. npm run beautify) so that I don't have to worry about the beautification process.
If any such thing can be done which automatically adds a commit to the current pull request which beautifies all the files, even that works fine.
I am ok with using any free third party softwares (Greenkeeper, travis or whatever)
You can use a git hook both on server and local or set up local filters (smudge/clean) to beautify your code before it even being committed to the repo.
Git hooks
Read the official docs for a full reference.
Smudge / clean
Read all about it and to set it up here:
https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes
It turns out that you can write your own filters for doing substitutions in files on commit/checkout.
These are called clean and smudge filters.
In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out (“smudge”, see Figure below) and just before they’re staged (“clean”, see Figure 8-3).
These filters can be set to do all sorts of fun things.