-
Notifications
You must be signed in to change notification settings - Fork 0
Merge 'dev' to 'master' #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
df75216
6374db4
98b8d7f
1ad7719
0aa92a9
8226ec7
0580f38
736cd47
b9762bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| language: go | ||
|
|
||
| go: | ||
| - 1.8.3 | ||
|
|
||
| env: | ||
| matrix: | ||
| - PACKAGE_TYPE=deb | ||
| - PACKAGE_TYPE=rpm | ||
|
|
||
| #install files needed for deployment | ||
| before_install: | ||
| - sudo apt-get -q update | ||
| - sudo apt-get install -y make rpm ruby-dev build-essential | ||
|
|
||
| #install fpm used for building packages | ||
| install: | ||
| - gem install fpm --no-document | ||
|
|
||
| #test the code | ||
| script: | ||
| - make test | ||
|
|
||
| #build the packages | ||
| after_success: | ||
| - make pkg/$PACKAGE_TYPE | ||
|
|
||
| deploy: | ||
| provider: s3 | ||
| access_key_id: | ||
| secure: <travis encrypted id key> | ||
| secret_access_key: | ||
| secure: <travis encrypted access key> | ||
| bucket: <bucket name> | ||
| local-dir: ./pkg/$PACKAGE_TYPE | ||
| upload-dir: $PACKAGE_TYPE | ||
| acl: public_read | ||
| skip_cleanup: true | ||
| region: eu-central-1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| NAME := pkgname | ||
| URL := https://InsertUrl.here | ||
| DESC := "description" | ||
| MAINTAINER := "Maintainer name" | ||
| LICENSE := "License here" | ||
| DEPENDENCIES := "" #Add dependencies here and add '-d $(DEPENDENCIES)' to fpm in pkg/% block | ||
|
|
||
| PKGDIR := ./pkg | ||
| VERSION ?= $(shell cat ./VERSION) | ||
| PACKAGE_TYPE := deb rpm | ||
|
|
||
| PATH_BIN ?= /usr/bin | ||
|
|
||
| test: vet ## runs unit tests | ||
| go test -v ./... | ||
|
|
||
| vet: ## examines the go code with `go vet` | ||
| go vet ./... | ||
|
|
||
| $(PKGDIR): $(addprefix $(PKGDIR)/,$(PACKAGE_TYPE)) ## creates artifacts for all distributions | ||
|
|
||
| # PACKAGING | ||
| $(PKGDIR)/rpm: TARGET_ARTIFACT=rpm | ||
| $(PKGDIR)/rpm: FPM_DEPENDENCIES=rpm | ||
| $(PKGDIR)/rpm: TARGET_FILE=$(NAME)-$(VERSION)-x86_64.rpm | ||
| $(PKGDIR)/deb: TARGET_ARTIFACT=deb | ||
| $(PKGDIR)/deb: FPM_DEPENDENCIES=apt | ||
| $(PKGDIR)/deb: TARGET_FILE=$(NAME)_$(VERSION)_amd64.deb | ||
| $(PKGDIR)/%: build ## creates the artifact for a specific distribution | ||
| mkdir -p $(PKGDIR)/$* | ||
| fpm -s dir -t $(TARGET_ARTIFACT) \ | ||
| --name $(NAME) \ | ||
| --package ./pkg/$*/$(TARGET_FILE) \ | ||
| --category admin \ | ||
| --deb-compression bzip2 \ | ||
| --url $(URL) \ | ||
| --description $(DESC) \ | ||
| --maintainer $(MAINTAINER) \ | ||
| --license $(LICENSE) \ | ||
| --version $(VERSION) \ | ||
| --architecture amd64 \ | ||
| ./usr | ||
|
|
||
| # BUILD | ||
| build: ## builds the code | ||
| mkdir -p .$(PATH_BIN) | ||
| GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -o .$(PATH_BIN)/$(NAME) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,15 @@ | ||
| # lambdaRepos | ||
| POC for managing RPM and DEB repositories using aws' S3 and λ | ||
|
|
||
| # Info | ||
| Code for managing `yum`(rpm) repository is located in [rpm folder](https://github.com/tactycal/lambdaRepos/tree/master/rpm) | ||
|
|
||
| Code for managing `apt`(deb) repository is located in [deb folder](https://github.com/tactycal/lambdaRepos/tree/master/deb) | ||
|
|
||
| Both folders contain more detailed info on setting up S3 bucket and lambda function, that keeps your repo in sync with provided packages | ||
|
|
||
| ## Combining with TravisCI | ||
|
|
||
| It is possible to automate deployment of packages by combining this repository with Travis CI. | ||
|
|
||
| Examples of `.travis.yml` and `Makefile` used for autamatic deployment of go project can be found in repository | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. automatic |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ZIPPED := s3apt.py gnupg.py debian/* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be formatted in a better way :) |
||
|
|
||
|
|
||
| set: requires package | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should |
||
|
|
||
| requires: | ||
| pip install -t . -r requirements.txt | ||
|
|
||
| package: | ||
| zip code.zip $(ZIPPED) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's always a good idea to also add |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
|
|
||
| # AWS Lambda APT repository manager for S3 | ||
|
|
||
| Rewrite of [szinck/s3apt](https://github.com/szinck/s3apt) with a few changes and extra features - Release file is being generated and is signed with GPG key provided | ||
|
|
||
| ## Setting up S3 and Lambda | ||
|
|
||
| Clone the repo and get all other required files | ||
| ``` | ||
| git clone https://github.com/tactycal/lambdaRepos.git | ||
| cd lambdaRepos/deb | ||
| pip install -t . -r requirements.txt | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have a make command in place for this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand, just use |
||
| ``` | ||
|
|
||
| Compress all needed files | ||
| ``` | ||
| zip code.zip s3apt.py gnupg.py debian/* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be updated |
||
| ``` | ||
| Or just use `make set` instead of `zip` and `pip` command | ||
|
|
||
| Presuming you already have GPG key generated export secret key (you can skip this part if you don't want to GPG sign your repository) | ||
| ``` | ||
| gpg -a --export-secret-key > secret.key | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some steps how to create the key if you don't have one already? |
||
| ``` | ||
|
|
||
| Create new lambda function, set handler to **s3apt.lambda_handler**, runtime to **python 2.7** and triggers to: | ||
|
|
||
| * Object Created(All), suffix 'deb' | ||
| * Object Removed(All), suffix 'deb' | ||
| * If you are using certain directory as a repo, set it as prefix | ||
|
|
||
| Upload `code.zip` to lambda function | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to replace this with AWS' CLI? |
||
|
|
||
| Set the environmental variables | ||
|
|
||
| | Key | Value | | ||
| | --- | ---| | ||
| | PUBLIC | True/False | | ||
| | GPG_KEY | File | | ||
| | GPG_PASS | GPG key password | | ||
| | BUCKET_NAME | Bucket Name | | ||
| | CACHE_PREFIX | Directory | | ||
|
|
||
| **PUBLIC** Set to `True` for the outputs to be publicly readable | ||
|
|
||
| **GPG_KEY** Location of your GPG private key from root of the bucket (e.g. secret/private.key). Not providing this variable will cause lambda to skip GPG singing | ||
|
|
||
| **GPG_PASS** Password of private key uploaded to GPG_KEY (Note: environmental variables are/can be encrypted using KMS keys) | ||
|
|
||
| **BUCKET_NAME** Name of the bucket. Should be the same as the one selected in triggers and the one you're using for repository | ||
|
|
||
| **CACHE_PREFIX** Path to folder for packages cache(e.g. deb/cache) | ||
|
|
||
| Make folder in your S3 bucket with the same name as CACHE_PREFIX variable | ||
|
|
||
| Upload secret key file to location you specified as GPG_KEY | ||
|
|
||
| Upload .deb file to desired folder, lambda function should now keep your repository up to date | ||
|
|
||
| ## Setting up apt | ||
|
|
||
| First time set up | ||
| ``` | ||
| sudo echo "deb https://s3.$AWS_SERVER.amazonaws.com/$BUCKET_NAME/$PATH_TO_FOLDER_WITH_DEBIAN_FILES /" >> /etc/apt/sources.list | ||
| #an example of link "https://s3.eu-central-1.amazonaws.com/testbucket/repo" | ||
| #add public key to trusted sources - you have to export public key or use key server | ||
| apt-key add <path to key> | ||
| sudo apt update | ||
| sudo apt install <packages> | ||
| ``` | ||
|
|
||
| Upgrading package | ||
| ``` | ||
| sudo apt update | ||
| sudo apt upgrade | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| .deb, Release and Package files are and should be publicly accessible for previously mentioned method of setting up apt's sources list to work, if you don't want them to be, then change PUBLIC in environment variables to False and refer to szinck's guide [here](http://webscale.plumbing/managing-apt-repos-in-s3-using-lambda) | ||
|
|
||
| If somebody tries to inject a malicious deb file in your repo it will be automaticly added to repository. It is your job to make bucket secure enough for this not to happen.!!! | ||
|
|
||
| **You should change lambda timeout to 10 seconds or more to make sure that function will work** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| boto3==1.3.1 | ||
| botocore==1.4.41 | ||
| docutils==0.12 | ||
| futures==3.0.5 | ||
| jmespath==0.9.0 | ||
| python-dateutil==2.5.3 | ||
| python-debian==0.1.28 | ||
| six==1.10.0 | ||
| python-gnupg==0.4.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the already existing formatting.