Apr 27, 2019 by Thibault | 1474 views
SimpleRepos is a simple file sharing website that allows to upload files using a REST API. Here is how to use it in conjunction with GitLab to automatically release your binaries...
You will need a running web server (like one from DigitalOcean for example) and a GitLab project with a working Continus Integration (.gitlab-ci.yml).
On your webserver, download the latest release of SimpleRepos from https://download.cylab.be/simple-repos
Extract the archive
Copy the example env file and modify it to fit your needs. Don't forget to modify the upload key!
cp env.example.prod .env nano .env
Install composer dependencies:
Configure the database:
php artisan migrate
SimpleRepos has a very simple REST API that allows to upload files. You can test it simply using curl on the command line:
export MY_TOKEN="upload_token_from_env_file" curl "http://my.server.com/api/readme.md" --request POST \\ --header "Authorization: Bearer $MY_TOKEN" -F 'file=@./readme.md'
You can now use GitLab CI to automatically upload your releases to your SimpleRepos server.
Here is an example snippet for your .gitlab-ci.yml:
stages: - test - build - release release: stage: release # This runs only when we push new tags only: - tags image: debian:stretch-slim script: - apt-get update -yqq - apt-get install -yqq zip ## We first create a zip for this release - ZIP_FILE="MY_PROJECT-$CI_COMMIT_TAG.zip" - zip $ZIP_FILE -r MY_PROJECT - "curl http://my.server.com/api/MY_PROJECT/$ZIP_FILE \\ --request POST --header \"Authorization: Bearer $UPLOAD_TOKEN\" \\ -F \"file=@./$ZIP_FILE\""
It would not be safe to write your upload token ($UPLOAD_TOKEN in the example above) directly in your git repository, hence you now have to define an environment variable in GitLab:
Now you can create and upload a release simply by creating a tag and pushing it to your GitLab repository:
git tag 0.0.1 git push --tags
This will automatically trigger the release script, that will build the zip and upload it to SimpleRepos...