Problem

Managed Redis instances are expensive. But Redis is amazing, I use it for handling cache, sessions and queues.
When speaking to the AWS team about ways of cutting our bills down they recommended moving to DynamoDB and SQS, my initial question was:

“How do I run the same stuff locally when developing so im not incurring costs?”

Their answer was:

“Just run it against a real instance?” - ¯_(ツ)_/¯

I’m really, really big on being able to run things locally. So I set out on working out how I could do the above.

Continue reading

I’ve pretty much switched to using docker for everything when doing local development now.

My set up involves using a docker-compose.yml file for the core application dependencies that can be run in production and a docker-compose.override.yml file for development. This override file is mostly a load of “support” containers that get used in development, things like php, artisan, npm as well as things like mysql and redis that would be handled elsewhere in production.

Since switching to this development model I’ve just accepted not getting around to getting BrowserSync working· This weekend whilst battling some other issues my fingers got tired of pressing ctrl+r every few seconds so I figured I’d give myself a win by trying to tackle this.

The Laravel mix docs have a brief section on BrowserSync but theres not enough to get BrowserSync working for our config.

Continue reading

Tailwind 2.x recommends using PostCSS for its preprocessor. However, if you still want to use Sass the documentation isn’t the clearest on how to set it up.

There is a page but it doesn’t seem to give you the step by step breakdown needed - here document whats needed to use Sass with Tailwind 2.x and Laravel-Mix.

First rename the resources/css/app.css file to use the scss extension:

mv resources/css/app.css resources/css/app.scss

Next remove the default postCss config within the webpack.mix.js config file:

// snip...
mix.postCss('resources/css/app.css', 'public/css', [
    require('postcss-import'),
    require('tailwindcss'),
    require('autoprefixer')
])

Now add the tailwind module and use the sass plugin and configure postCss to use the tailwind.config.js file:

const tailwindcss = require('tailwindcss')
// snip...
mix.sass('resources/css/app.scss', 'public/css')
    .options({ postCss: [ tailwindcss('./tailwind.config.js')]})

Thats it!

When you run npm run dev the needed sass and other js dependencies will be detected as missing and automatically installed.

Continue reading

In 2019 I wrote about how I get around static IP restrictions when working in different places.
The world is very different now and whilst I’m not travelling anymore I still use sshuttle regularly to make my traffic look like its coming from a given location.

Recently I started switching some of my projects to run on docker locally (annoyingly this was before Laravel Sail was announced). However one of the challenges with sshuttle + docker in the way I’d originally got things set up is your networking gets messed up and consequently nothing really works for the project - not ideal.

Thats not the end of the story though, there’s an easy fix here - exclude the docker subnets from sshuttle.

Continue reading

Adding A CI/CD process to my work flow is one of the really quick wins I do on every serious project I work on.

Whilst most of my personal work is hosted on Gitlab, a recent project I was working had its code in Bitbucket. This was my first time working with Bitbucket, so I wanted to document how I built assets, linted and ran tests using its pipelines.

What will these pipelines do?

By the end of this article you should have a working bitbucket-pipelines.yml file for your Laravel project which will do the following:

  • Use composer to install your projects dependencies
  • Run php-cs-fixer to enforce a code style
  • Run larastan to run static analysis against the code base
  • Run php-cs-fixer and larastan in parallel
  • Run phpunit to run our projects test suite
  • For a production build yarn run production
  • Allow us to manually trigger a deployment to production using Laravel Deployer.
Continue reading

Today I tried to set up my jigsaw-photo-stream project to use netlify large media with git-lfs.

What I failed to read was this key part of the netlify documentation:

Files tracked with Large Media are uploaded directly to the Netlify Large Media storage service on push, completely bypassing the site build.


As part of the build process for the project I resize the images that are uploaded.
The netlify documentation suggests that you could use netlify’s image transformation to get around this but ideally I dont want the project to be tied into the service provider should I want to migrate to another static site host.

At this point I’d already set up git-lfs on the repo and my netlify builds were failing.
I found this link to remove git-lfs from an existing repo

The steps being:

1
git lfs uninstall

remove lfs stuff from .gitattributes

1
2
3
4
5
6
7
8
git lfs ls-files | sed -r 's/^.{13}//' > files.txt
while read line; do git rm --cached "$line"; done < files.txt
while read line; do git add "$line"; done < files.txt
git add .gitattributes
git commit -m "unlfs"
git push origin
git lfs ls-files
rm -rf .git/lfs

Comment and share

Today I was working on an API written in Laravel for a React Native app with another developer.

He was trying to make requests to the Laravel backend and told me he kept receiving a response with a http status code of 302. 3XX http status codes are redirection status codes.

It turned out that he had not set an accept header on the requests to the server that the app was making.

By default if you dont set a requests accept headers they default to Accept: */*. With those set laravel responds with a Content-Type of text/html.

For the purpose of this project every api response needs to return JSON.

We can achieve this really easily by using middleware to overwrite the Accept headers on the incoming request and setting them to application/json.

Continue reading

At our company setting up gitlab ci configuration is one of the jobs I end up doing by default.

This weekend I wrote a package to help speed that process up by generating a .gitlab-ci.yml file as well as installing some of the packages and configuration files to make the following possible:

The package currently provides a single artisan command to do all of the above after answering a few simple questions.

Check the repo out here:

https://github.com/talvbansal/laravel-gitlab-ci-config-generator

Continue reading

Over the last couple of days of social distancing I spent some time working on a photostream site for some of my travel photos.

Whilst I usually post them on mine and my wife’s Instagram page iwantthewindowseat I’ve not found myself having the motivation to select an image, think of a caption, find hashtags and post at the best time for visibility as much as I used to.

I also wanted somewhere where copyright ownership wasn’t an issue. Much like this site is an archive of my ramblings and things I’ve worked on, I thought it would be cool to hav something similar for my photos.

This project was also a great opportunity to look at some of the newer browser features like lazy loading and leverage them - as of writing Firefox 74 is out and native lazy loading is due in Firefox 75. Native lazy loading is in chrome, the project uses a polyfill to bring lazy loading to older browsers.

Photo Stream

The project itself can be seen at iwantthewindowseat.netlify.com.

The code repository can be forked and cloned over here.

Comment and share

Recently I wrote about my current Gitlab CI process, when it came to the deployment part of the process I showed how I was handling it using a tool called Laravel deployer but I didn’t breakdown what laravel deployer was doing and how I had it configured.

The Laravel deployer docs are pretty good however I found a couple of server config issues that I always find myself referring back to when setting up auto deployment. Mostly to automatically restart Laravel Horizon and restarting Php-fpm without needing sudo privileges.

Lets imagine I was going to a set up Gitlab CI / CD for a fictional project hosted over on the fictional domain of deployer.talvbansal.com with a real repository here that is hosted on somewhere like Linode, Digital Ocean or even AWS.

Continue reading
Author's picture

Talv Bansal

Full Stack Developer, Part Time Photographer


Head of Software Engineering


Remote