Category: Shell

A tiny blog for DevOPS related items

Always in for coffee and cookies

Satis & S3

Prerequisites:

Satis is a static composer repository generator.
It does nothing more than creating an index of your packages, from the repositories you added in your Satis configuration.

It’s alse possible to use Satis as a proxy for packages found on Packagist, GitHub or any other repository.

When i started with Satis, i hosted it on a small server which required Apache to serve Satis.
Because the number of packages and repositories grew as i started to work on bigger and more projects, i ran into the “limitations” of hosting Satis on a webserver.

These weren’t really limitations, but i figured that using a webserver was actually overkill because Satis is nothing more than static content.

This is where AWS S3 came in the picture.
S3 is perfect for serving static content without the need of a webserver.
A big advantage is that you don’t pay a lot for storage,or traffic.
And when first registering an AWS account, you are eligable for the free tier. (See: https://aws.amazon.com/s3/pricing/)

So no more worries for large Satis configurations!

So how did i do this?
Actually, very little changed in the way we generate our Satis files.
My satis configuration has its own repository, so i can add new repositories when needed. Whenever a pull request is merged into the mainline, a build agents picks up on this change
and starts to build Satis.
Nothing exiting is going on there.

I removed the existing Satis build and create a new one:

$ rm -rf web/include/* satis build -n -vvv satis.json web/ 

This process might take a while of you have a lot of repositories.
Depending on your Satis configuration, all package version might be downloaded.
This is preferred by me, because not all projects have to (or can) use the latest version of a package.
And since S3 is pretty limitless when it comes to storage, i’ll just download everything.

The configuration that makes sure i want to use Satis as a proxy is as follows:

{
    "require-all": true,
    "archive": {
        "directory": "dist",
        "format": "tar",
        "skip-dev": true,
        "whitelist": [
            "<manufacturer>/<package>",
        ]
    }
}

The whitelist flag is optional.
When left out, every package, version and dependancy is archived.
It’s up to you do decide what you want to proxy. Creating projects with as many packages from your proxy speeds up the composer install precess quite a bit, because composer doesn’t hae to clone every repository.

After the Satis build is done, you want to upload/sync everything inside ‘web/’ to S3.

My build agent has the AWS CLI binary installed, so this is pretty easy:

$ aws s3 sync --delete . s3://<your-bucket>/

This will sync your Satis build to S3, and will remove any packages that are no longer present within Satis.

That’s it. Now your satis build is usable from AWS S3.

If you want to use a more human friendly domain, you could use CloudFront to serve the files I’ve written a small article on how to accomplish this