switchon@lavalamp.biz
+27(0) 83 419 4851 / +27(0) 21 036 1165
Application & software development
Get A Quote

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact
    how we made a build server using webhooks, fastlane and bash (part 1)
    How We Made A Build Server Using Webhooks, Fastlane And Bash (Part 2)
    Jan 27, 2019

    How We Made A Build Server Using Webhooks, Fastlane And Bash (Part 1)

    Categories
    • Software Development
    Tags
    • bash
    • bitbucket
    • devops
    • fastlane
    • local build server
    • server
    • software development
    • webhook
    • webhook server
    • workstation
    how we made a build server using webhooks, fastlane and bash (part 1)
    how we made a build server using webhooks, fastlane and bash (part 1)

    This is the first blog post in a series about how we built a simple build server using webhooks and fastlane

    Here is a picture illustrating the architecture we used.


    After a developer pushes to the repository, information in a webhook is sent to a server in the cloud that we manage. The server has a connection to our local build server through ZeroTier. The webhook server passes the information to the local build server and the build server does the rest. The build server pulls code, runs tests and distributes builds depending on the information in the webhook and information in the repository it's building.

    In this post I'm going to show how we setup the webhook server.


    1. Download and install webhook onto your server


    First, we needed a server that can receive HTTP requests (webhooks) from the repository and run scripts based on them. In other words it needs to have a webhook API. We used an executable written in Golang called webhook to receive the webhooks. This can be found here.

    After installing we set it up to run with options:

    webhook -hooks /path-to-hooks-file/hooks.json -verbose -port 9001 -ip 127.0.0.1 -hotreload

    -hooks /path-to-hooks-file/hooks.json specifies the path to the hooks file which we will show in the final step.
    -verbose is for verbose logging.
    -port 9001 and -ip 127.0.0.1 show where the webhook program is listening for webhooks.
    -hotreload specifies that when the hooks file is changed the server automatically picks up on the changes. This link is useful list showing all the options for webhook.

    Although we have not set webhook up to keep running, we have script that contains the following that we run to keep it going in the background:

    (webhook -hooks /path-to-hooks-file/hooks.json -verbose -port 9001 -ip 127.0.0.1 -hotreload &) &> webhook_logs

    That script runs webhook in the background so you can log out of the server and it keeps running. All logs are also written to the webhook_logs file.


    2. Connect server to outside world (nginx)


    We create the following in an nginx configuration file which sends the /hook/ endpoint to port 9001 where the webhook server is listening.

    server {
        server_name    example.com
        location /hook/
        {
            proxy_pass https://127.0.0.1:9001/hooks/;
            proxy_set_header    Host                $host;
            proxy_set_header    X-Real-IP           $remote_addr;
            proxy_set_header    X-Forwarded-For     $remote_addr;
            proxy_set_header    X-Forwarded-Proto   $scheme;
            proxy_redirect      off;
        }
    }
    

    3. Specify hooks in json input file (bitbucket example)


    A sample hooks.json file set up for bitbucket is shown here:

    [{
        "id": "ios-push-webhook",
        "execute-command": "https://lavalamplab.b-cdn.net/home/username/notify_build_server.sh",
        "command-working-directory": "/home/username",
        "pass-arguments-to-command":
        [
          {
            "source": "payload",
            "name": "actor.username"
          },
          {
            "source": "payload",
            "name": "push.changes.0.new.type"
          },
          {
            "source": "payload",
            "name": "push.changes.0.new.name"
          },
          {
            "source": "payload",
            "name": "push.changes.0.new.target.hash"
          },
          {
            "source": "payload",
            "name": "push.changes.0.new.target.message"
          }]
    }]
    

    "id": "ios-push-webhook" is the path of the webhook in the url.

    "execute-command": "https://lavalamplab.b-cdn.net/home/username/notify_build_server.sh" is the script that gets run by the webhook

    "command-working-directory": "/home/username" specifies the directory in which the command gets run

    "pass-arguments-to-command" specifies an array of arguments that are sent to the command. In this example the payload of the webhook from bitbucket is parsed into command arguments. The description of the payload is here. Which includes:

    • The name of the person who made the push
    • What kind of push it was
    • The name of the branch
    • The hash of the commit
    • The commit message

    Next time


    The script that gets run simply takes the arguments and passes them on to the build server, along with which repo the push was made to. That will be the topic of the next blog post, Where we will show the connection to the build server as well as the script that handles the jobs for making builds.

    Contact us


      Related posts:

      how we made a build server using webhooks, fastlane and bash (part 1)How We Made A Build Server Using Webhooks, Fastlane And Bash (Part 2) how to setup git-ftp for windowsHow To Setup Git-ftp For Windows laravel envoyer and forgeProvisioning A New Digital Ocean Server With Laravel Forge, And Deploying Code With Laravel Envoyer implementing laravel echoImplementing Laravel Echo And Socket.io With A Laravel API And Ionic Vue App
      Share
      42
      Tielman Janse van Vuuren
      Tielman Janse van Vuuren
      Tielman is an experienced mobile and backend developer. Quality is his motto, no matter what programming language or platform.

      Leave a Reply Cancel reply

      Your email address will not be published. Required fields are marked *

      Lava Lamp Lab


      Like technology, a lava lamp constantly changes form, producing new conditions with every passing moment



      lava lamp lab facebook   lava lamp lab twitter   lava lamp lab linkedin   lava lamp lab instgram

      Services


      Application & software development

      Outsourced software development

      Project based resourcing

      Digital marketing & consulting

      Graphic design & consulting

      UI / UX design & consulting

      Contact Us


      +27(0) 83 419 4851

      +27(0) 21 036 1165


      switchon@lavalamp.biz


      Unit 4 Monaco Square,
      14 Church Street,
      Durbanville,
      Cape Town, 7550

      NBConsult Group


      nbconsult
      nbconnect msp
      nbclearning
      river broadband
      designer needed
      © 2023 Lava Lamp Lab (Pty) Ltd | All Rights Reserved | Privacy Policy
      Contact us now

        Application & software development

          Outsourced software development

            Project based resourcing

              Digital marketing & consulting

                Graphic design & consulting

                  UI/UX design & consulting

                    Lease an expert

                      Recruitment services

                        We are using cookies to give you the best experience on our website.

                        You can find out more about which cookies we are using or switch them off in settings.

                        Lava Lamp Lab
                        Powered by  GDPR Cookie Compliance
                        Privacy Overview

                        This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

                        Strictly Necessary Cookies

                        Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

                        If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

                        3rd Party Cookies

                        This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

                        Keeping this cookie enabled helps us to improve our website.

                        Please enable Strictly Necessary Cookies first so that we can save your preferences!

                        Cookie Policy

                        More information about our Cookie Policy