Created
August 25, 2019 10:10
-
-
Save dieterrosch/3ee86773f2be59fba2ccaf535183a564 to your computer and use it in GitHub Desktop.
Given a source directory that contains a go package, create a go module that is hostable on a regular HTTP server (in this case an S3 bucket)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Given a directory containing a Go module, converts it to a | |
# package in the format required to be hosted on standard HTTP server | |
#!/bin/bash | |
if [ $# -ne 6 ] | |
then | |
echo "Usage: $0 <source_directory> <output_directory> <slug> <package> <version> <S3_bucket_name" | |
echo "Eg: $0 my_code_pkg/ output_dir example.com mymodule \"1.0.0\" my-bucket" | |
exit 1 | |
fi | |
INPUT_DIR=$1 | |
OUTPUT_DIR=$2 | |
SLUG=$3 | |
PACKAGE=$4 | |
VERSION=$5 | |
BUCKET_NAME=$6 | |
DEST=$OUTPUT_DIR/$SLUG/$PACKAGE/@v | |
PACKAGE_LOCATION=$DEST/$SLUG/$PACKAGE@v$VERSION | |
mkdir -p $PACKAGE_LOCATION | |
cp -R $INPUT_DIR/* $PACKAGE_LOCATION | |
cd $PACKAGE_LOCATION | |
go mod init $SLUG/$PACKAGE | |
cd - | |
mv $PACKAGE_LOCATION/go.mod $DEST/v$VERSION.mod | |
JSON_STRING=$( jq -n \ | |
--arg jsonversion "v$VERSION" \ | |
--arg jsontimenow `date --rfc-3339=seconds | sed 's/ /T/'` \ | |
'{Version: $jsonversion, Time: $jsontimenow}' ) | |
echo Creating file $DEST/v$VERSION.info with JSON contents: $JSON_STRING | |
echo $JSON_STRING > $DEST/v$VERSION.info | |
cd $DEST | |
echo $PWD | |
zip -r $PACKAGE@v$VERSION.zip $SLUG/* | |
#UPLOAD to S3 bucket | |
aws s3 cp --acl=public-read $PACKAGE@v$VERSION.zip s3://$BUCKET_NAME/$SLUG/$PACKAGE/@v/ | |
aws s3 cp --acl=public-read v$VERSION.info s3://$BUCKET_NAME/$SLUG/$PACKAGE/@v/ | |
aws s3 cp --acl=public-read v$VERSION.mod s3://$BUCKET_NAME/$SLUG/$PACKAGE/@v/ | |
echo "Package uploaded!!! Remember to set you GOPROXY, eg." | |
echo "export GOPROXY=http://$BUCKET_NAME.s3-website-eu-west-1.amazonaws.com" | |
echo "and then test the package download with" | |
echo "go get -v $SLUG/$PACKAGE@v$VERSION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment