Category: Uncategorized

  • Setting billing cap on Google Cloud Platform

    Setting billing cap on Google Cloud Platform

    You can setup pricing alerts on GCP in the Budgets & alerts but there seems to be no way to set hard billing cap. Meaning, if your spending reaches x amount the service(s) just stops.

    Fortunately Youtuber called Data Slayer has created nice YouTube tutorial here https://www.youtube.com/watch?v=KiTg8RPpGG4 together with GitHub repo here: https://github.com/aioverlords/Google-Cloud-Platform-Killswitch

    You can combine budget pub/sub alerts with a cloud function that can disable billing on your entire account if a threshold is met.

    In shot

    const _disableBillingForProject = async projectName => {
    const res = await billing.updateBillingInfo({
        name: projectName,
        resource: {
            billingAccountName: ''
        }, // Disable billing
    });
    console.log(res);
    console.log("Billing Disabled");
    return `Billing disabled: ${JSON.stringify(res.data)}`;
    };

  • 3 Ways to Center a Div

    Somehow I always seems to struggle to center block elements so I write a small note (mostly for myself) how to do it.

    1. Old School margin:auto

    div{
    margin-left: auto;
    margin-right: auto;
    }

    2. Flex and the justify-content

    div{
    display:flex;
    height:100vh;
    align-items:center:
    justify-content:center;
    
    }

    3. Grid and setting the place-items

    div{
    display:grid;
    height:100vh;
    place-items: center;
    }
  • Umbraco Continuous Deployment with Jenkins

    Umbraco Continuous Deployment with Jenkins

    I haven’t seen many posts about Continuous Integration. Perhaps this is because Umbraco Cloud option offers this feature off the shelf but I have some customers that require customizations (custom databases) that would be costly on the Umbraco Cloud setup. Therefore I decided to spin up Jenkins that connects to Github repo and does automatic deployment from the main branch whenever there is push to it.

    Here are few quick steps that gets you started.

    1. Setup Github

    Wheater you use Github or Gitlab or your own Git repo these steps do not matter. You just need a branching stradegy where the master branch matches what is in your live site.

    image of release branch workflows

    Merge feature branches into the master branch using pull requests.

    Install Jenkins

    I have root server Windows 2019 running on Hetzner but I hear OVHCloud is good as well. So, I installed Jenkins instances directly on my test server and live server. I could do the setup with PowerShell remote but Jenkins is quick to install and requires very little maintainance and resources so I just have them running isolated on the given server.

    In the Jenkins server you also need Microsoft Build Tools and Nuget installed on globally available.

    Configure Jenkins for Umbraco

    You need some plugins in order to build .NET projects and Frontend projects. Try these:

    • MBBuild
    • Global Slack Notifier Plugin (for notifying build success/failures)
    • NodeJS Plugin (control npm builds)
    • Nuget Plugin
    • PowerShell plugin (for scripting)
    • ThinBackup (for moving Jenkins configs between instances

    Here is my sample configuration on Freestyle Jenkins project.

    Node version

    Nuget restore command and Injection to Assembly

    Run MSBuild

    Copy files from Jenkins build folder to Webroot


    Notice that running IISReset here is probably not the best idea. I have done same thing on Sitecore projects where instead I stop/start Application Pool. Stop-WebAppPool -Name "DefaultAppPool" you may make restarting of the application few seconds faster that way. But you need to stop AppPool or IIS because sometiimes artificats are locked and if that happens things goes south.

    Post Build actions

    You can also setup here Email notification or if you use Teams , RocketChat etc. there is plugins for sending notification when build completes or fails.
    If you work on bigger team you can also send email for whoever pushed bad code on the success/failure.

    That’s it. Minimail Jenkins setup for Umbraco projects that I use. This same setup works for any .NET projects as I did not include any actions on uSync or anything other Umbraco specific.

    I have done few DevOps Setups on Jenkins, TeamCity, Azure Devops and Github Actions. Which ever CI/CD tool you are using I recommend to create your scriptinigs on Node and/or PowerShell so you can easily jump between as they all work essentially same way.

  • Quick Screen -command reference

    Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).

    DescriptionCommand

    Start a new session with session name
    screen -S <session_name>
    List running sessions / screensscreen -ls
    Attach to a running sessionscreen -x
    Attach to a running session with namescreen -r <session_name>
    Detach a running sessionscreen -d <session_name>

    Switching between screens

    When you do nested screen, you can switch between screen using command “Ctrl-A” and “n“. It will be move to the next screen. When you need to go to the previous screen, just press “Ctrl-A” and “p“.

    To create a new screen window, just press “Ctrl-A” and “c“.

    Leaving Screen

    There are 2 (two) ways to leaving the screen. First, we are using “Ctrl-A” and “d” to detach the screen. Second, we can use the exit command to terminating screen. You also can use “Ctrl-A” and “K” to kill the screen.

    That’s some of screen usage on daily basis. There are still a lot of features inside the screen command. You may see screen man page for more detail or this page https://gist.github.com/jctosta/af918e1618682638aa82.

  • I don’t use anymore “cloud” providers for personal projects.

    I love Azure Functions for small jobs and deploying Kubernetes cluster from Github actions to Amazon EKS is blast. But I think it is only business customers and not for small startups or pet projects.

    At work I am using Azure and AWS and I used to have GCP and AWS for my pet projects as well but now my projects run on Hetzner VPS’s and Cloud. Main reason for my decision to favour Hetzner over these big guys is uncertaincy and confusion of billing. It’s nice if I suddenly become next Facebook to have scaling possibilty but that is least of my worries and quite nice problem to have. What I like VPS’s and Hetzner Cloud is straight forward and simple pricing per month. If I want Cloud instance with 2Gb RAM and 1vCPU it’s 3 Euros. If I run out of resources I can scale up like going to 32Gb is 35 Euros.

    I have small startup where I have worker process written on Python, API written on Node and client running as SPA (Vue.js/Nuxt.js). Data layer is on PostgreSQL/Redis. Without thinking, I set this up in AWS and it worked nicely but soon I noticed this is 100 Euros/month. Since this is in Minimum Viable Product stage I decided to move to VPS. So I spin up VPS with Ubuntu on it. I deployed everything there and changed Github actions. It took me one evening and I don’t consider myself sysadmin. But I think installing Linux with above tech stack is easier than to understand how to run same setup on AWS, GCP or Azure. If in some point I need scaling I can always move back Kubernetes setup on AWS but sometimes less is more.

  • New blog

    I started new blog here.

    But right now I am busy with customer projects but soon I will start to push some content here.

  • My essential brew tools

    brew install awscli
    brew install cask
    brew install cocoapods
    brew install httrack
    brew install n
    brew install node
    brew install pkg-config
    brew install tree
    brew install wget
    brew install zsh
  • Restart Windows on certain time

    Restart Windows on certain time

    schtasks /create /tn "reboot for updates" /tr "shutdown /r /t 0" /sc once /st 23:27:00 /sd 11/13/2019 /ru "System"

    What is this?

    Schtasks

  • 4 Useful extension for Visual Studio Code

    4 Useful extension for Visual Studio Code

    Bracket Pair Colorizer

    This extension allows matching brackets to be identified with colours. The user can define which tokens to match, and which colours to use.

    Bracket Pair Colorizer

    Git graph

    View a Git Graph of your repository, and easily perform Git actions from the graph. Configurable to look the way you want!

    Git Graph

    GitLens

    Visualize code authorship at a glance.

    GitLens

    Live Share

    Real-time collaborative development.

    Live Share

  • App Engine vs Cloud Functions

    App Engine vs Cloud Functions

    Both Cloud Functions (CFs) and Google App Engine (GAE) are designed to build “microservice architecture” in the “serveless” environment.

    Google says that Cloud Functions is basically for SERVERLESS FUNCTIONS & EVENTS where as App Engine is for SERVERLESS HTTP APPLICATIONS. However,when I read this short description I am still confused since if I am running SPA application what prevents me to use just CFs for my serverside code? When exactly would use GAE instead of CFs?

    I made a small investigation on this and here are my findings.

    Little bit more longer description from Google:

    Cloud Functions

    An event-driven compute platform to easily connect and extend Google and third-party cloud services and build applications that scale from zero to planet scale.

    Use Cases

    • Asynchronous backend processing
    • Simple APIs (like one or two functions, not RESTful stuff)
    • Rapid prototyping and API stitching

     

     

    App Engine standard environment

    A fully managed serverless application platform for web and API backends. Use popular development languages without worrying about infrastructure management.

    Use Cases

    • Web applications
    • API’s like Mobile and SPA backends

     

     

     

    I found this answer from StackOverflow which I am updating here with few of my edits.

    When creating relatively complex applications, CFs have several disadvantages compared to GAE.

    • Limited to Node.JS, Python, and Go. GAE supports also .NET, Ruby, PHP, Java.
    • CFS is designed for lightweight, standalone pieces of functionality, attempting to build complex applications using such components quickly becomes “awkward”. Yes, the inter-relationship context for every individual request must be restored on GAE just as well, only GAE benefits from more convenient means of doing that which aren’t available on CFs. For example user session management, as discussed in other comments
    • GAE apps have an app context that survives across individual requests, CFs don’t have that. Such context makes access to certain Google services more efficient/performant (or even plain possible) for GAE apps, but not for CFs. For example memcached.
    • the availability of the app context for GAE apps can support more efficient/performant client libraries for other services which can’t operate on CFs. For example accessing the datastore using the ndb client library (only available for standard env GAE python apps) can be more efficient/performant than using the generic datastore client library.
    • GAE can be more cost effective as it’s “wholesale” priced (based on instance-hours, regardless of how many requests a particular instance serves) compared to “retail” pricing of CFs (where each invocation is charged separately)
    • response times might be typically shorter for GAE apps than CFs since typically the app instance handling the request is already running, thus:
      • the GAE app context doesn’t need to be loaded/restored, it’s already available, CFs need to load/restore it
      • the handling code is (most of the time) already loaded, CFs’ code still needs to be loaded. Not to sure about this one, tho, I guess it depends on the underlying implementation.

    Note that nothing prevents us from mixing both notions. An AppEngine application can launch jobs through cloud functions

    Summary

    Use Cloud Functions (CFs) for “tasks” and use Google App Engine (GAE) for “full applications”.