Coder Social home page Coder Social logo

Auto deploy webhook FILTER about dokploy HOT 7 CLOSED

hikinine avatar hikinine commented on July 18, 2024
Auto deploy webhook FILTER

from dokploy.

Comments (7)

Siumauricio avatar Siumauricio commented on July 18, 2024 1

Thank you, and good analysis that's how really works dokploy under the hood in deployments terms.

You are right, it will deploy only the tag you selected, but in your case you pushed 3 images at the same time it will create 3 deployments obviously with the same tag, but is not ideal to redeploy 3 times the same tag, We need to apply a filter there to prevent the deployments when you push another tag, the same as we do in github when the branch doesnt match it will return 301, We can do the same, altought is not a big problem for now but would be ideal to do make this little detail.

Would you ve up to make a PR?

from dokploy.

hikinine avatar hikinine commented on July 18, 2024 1

Would you ve up to make a PR?

I'll be happy to work on it

from dokploy.

Siumauricio avatar Siumauricio commented on July 18, 2024

I understand the problem, definitely the easiest solution would be to filter by the tag chosen in the docker setup provider, this would make it easier

from dokploy.

hikinine avatar hikinine commented on July 18, 2024

I understand the problem, definitely the easiest solution would be to filter by the tag chosen in the docker setup provider, this would make it easier

You are right, problem is that dockerhub does not offer any support to filter / condition webhook triggers.
Maybe with github webhook i can achieve that behaviour.

Thanks for the reply!

from dokploy.

Siumauricio avatar Siumauricio commented on July 18, 2024

Yeah, what i mean is we can change the behavior in the endpoint where we recieve the webhook, and filter by the tag you specified in the docker provider, I think this will have more sense, because if tou specified a specific tag, you expect to be deployed only on that specific tag, in fact this is what we do on GitHub provider and git provider, we filter by the branch

from dokploy.

hikinine avatar hikinine commented on July 18, 2024

With github integration worked as expected.
Kinda different workflow since now its listening to "push" on specified branch and then building that source code and deploying.

I'm still a little worried about build the application in the same machine that I use for production apps (maybe its just over thinking since my apps are lightweight).

Anyway,
I'm studying the dokploy architecture a little bit. As I understood,

1 - Dokploy listens to http request on /api/deploy/<refreshToken> (which do we pass to providers dockerhub, etc..)
2 - Find application by using provided token
3 - If application deploy sourceType is git / github:
-> Ensure that webhook payload matchs with provided branch (if not, ends with 301 status)
4 - Push deployments to queue.

const sourceType = application.sourceType;
if (sourceType === "github") {
const branchName = extractBranchName(req.headers, req.body);
if (!branchName || branchName !== application.branch) {
res.status(301).json({ message: "Branch Not Match" });
return;
}
} else if (sourceType === "git") {
const branchName = extractBranchName(req.headers, req.body);
if (!branchName || branchName !== application.customGitBranch) {
res.status(301).json({ message: "Branch Not Match" });
return;
}
}

5 - deployments worker start job execution.
6 - Processor execute deployApplication which will execute deploy action based on sourceType
Lets say our sourceType is "docker".

7 - Execute dockerBuild which will docker pull the image with provided setup (including tag).

Looks like dokploy is not deploying the other tags, which is great... I mean, we dont read the webhook payload. It is used only to trigger the deploy (which i think is the right choice).

Its a fake data (titleLog naming event payload)

dokploy took from webhook payload the name from tags (production, staging, etc) but it never deployed every image... It only repeat the same deploy for the initial provided tag image
image

So... there is no problem (only multiple deploy of the same image)

Solution

if (sourceType === 'docker') {
    const currentTagName = getTagFromDockerImage(application.dockerImage) ?? 'latest'


   if (currentTagName) {
      const requestBody =  request.body // i dont know how to access it
     // https://docs.docker.com/docker-hub/webhooks/?_gl=1*1ksgu74*_ga*NjA2MjQ5NTU3LjE3MTY1NTI4ODc.*_ga_XJWPQMJYHQ*MTcxNjU5Mjc5OS4zLjEuMTcxNjU5MzI2NS41Ny4wLjA.
      const payloadTagName = requestBody.push_data.tag
      if (payloadTagName  !== currentTagName) {
           res.status(301).json({ message: "Branch Not Match" });
	   return;
      }
   }

}
if (sourceType === "github") {
			const branchName = extractBranchName(req.headers, req.body);
			if (!branchName || branchName !== application.branch) {
				res.status(301).json({ message: "Branch Not Match" });
				return;
			}
		} else if (sourceType === "git") {
			const branchName = extractBranchName(req.headers, req.body);
			if (!branchName || branchName !== application.customGitBranch) {
				res.status(301).json({ message: "Branch Not Match" });
				return;
			}
		}

from dokploy.

hikinine avatar hikinine commented on July 18, 2024

Here is the titleLog.
Appears like it is deploying the image described. But its only log purpose (deployed tag is always the provided on initial config)

if (headers["user-agent"]?.includes("Go-http-client")) {
if (body.push_data && body.repository) {
return `Docker image pushed: ${body.repository.repo_name}:${body.push_data.tag} by ${body.push_data.pusher}`;
}
}

from dokploy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.