Skip to content

Commit

Permalink
Full deployment workflow: push finished assets to DigitalOcean Spaces…
Browse files Browse the repository at this point in the history
… (cdn.kmkfw.io)
  • Loading branch information
klardotsh committed Jul 25, 2019
1 parent cd7d8a2 commit 39e3a65
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 61 deletions.
30 changes: 2 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,18 @@ jobs:

environment:
KMK_TEST: 1
PIPENV_VENV_IN_PROJECT: 1

steps:
- checkout
- restore_cache:
keys:
- v2-kmk-venv-{{ checksum "Pipfile.lock" }}

- run: make dist

test:
docker:
- image: 'kmkfw/base'

environment:
KMK_TEST: 1
PIPENV_VENV_IN_PROJECT: 1

steps:
- checkout
- restore_cache:
keys:
- v2-kmk-venv-{{ checksum "Pipfile.lock" }}

- run: make test
- run: make dist
- run: make dist-deploy

workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
branches:
# only: /master/
only: /.*/
tags:
only: /.*/
- test:
filters:
branches:
only: /.*/
Expand Down
81 changes: 81 additions & 0 deletions .s3cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[default]
access_key =
access_token =
add_encoding_exts =
add_headers =
bucket_location = US
ca_certs_file =
cache_file =
check_ssl_certificate = True
check_ssl_hostname = True
cloudfront_host = cloudfront.amazonaws.com
content_disposition =
content_type =
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encoding = UTF-8
encrypt = False
expiry_date =
expiry_days =
expiry_prefix =
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = sfo2.digitaloceanspaces.com
host_bucket = %(bucket)s.sfo2.digitaloceanspaces.com
human_readable_sizes = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
kms_key =
limit = -1
limitrate = 0
list_md5 = False
log_target_prefix =
long_listing = False
max_delete = -1
mime_type =
multipart_chunk_size_mb = 15
multipart_max_chunks = 10000
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 65536
reduced_redundancy = False
requester_pays = False
restore_days = 1
restore_priority = Standard
secret_key =
send_chunk = 65536
server_side_encryption = False
signature_v2 = False
signurl_use_https = False
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
stats = False
stop_on_error = False
storage_class =
throttle_max = 100
upload_id =
urlencoding_mode = normal
use_http_expect = False
use_https = True
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://%(bucket)s.s3-website-%(location)s.amazonaws.com/
website_error =
website_index = index.html
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM python:3.7-alpine
RUN mkdir -p /app
WORKDIR /app

RUN apk update && apk add alpine-sdk curl gettext git git-lfs openssh rsync wget zip
RUN apk update && apk add alpine-sdk coreutils curl gettext git git-lfs openssh rsync wget zip

RUN pip install pipenv

Expand Down
42 changes: 27 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,51 @@ MPY_CROSS ?= $(shell which mpy-cross 2>/dev/null)
MPY_FLAGS ?= '-O2'
MPY_SOURCES = 'kmk/'
MPY_TARGET_DIR ?= .compiled
PY_KMK_TREE = $(shell find $(MPY_SOURCES) -name "*.py")
DIST_DESCRIBE = $(shell $(DIST_DESCRIBE_CMD))

all: copy-kmk copy-bootpy copy-keymap

compile: $(MPY_TARGET_DIR)/.mpy.compiled

$(MPY_TARGET_DIR)/.mpy.compiled: $(shell find $(MPY_SOURCES) -name "*.py")
$(MPY_TARGET_DIR)/.mpy.compiled: $(PY_KMK_TREE)
ifeq ($(MPY_CROSS),)
@echo "===> Could not find mpy-cross in PATH, exiting"
@false
endif
@echo "===> Compiling all py files to mpy with flags $(MPY_FLAGS)"
@mkdir -p $(MPY_TARGET_DIR)
@find $(MPY_SOURCES) -name "*.py" -exec sh -c 'mkdir -p $(MPY_TARGET_DIR)/$$(dirname {}) && mpy-cross $(MPY_FLAGS) {} -o $(MPY_TARGET_DIR)/$$(dirname {})/$$(basename -s .py {}).mpy' \;
@touch $(MPY_TARGET_DIR)/.mpy.compiled

dist: dist/latest.zip dist/latest.unoptimized.zip dist/$(shell $(DIST_DESCRIBE_CMD)).zip dist/$(shell $(DIST_DESCRIBE_CMD)).unoptimized.zip
dist: dist/latest.zip dist/latest.unoptimized.zip dist/$(DIST_DESCRIBE).zip dist/$(DIST_DESCRIBE).unoptimized.zip

dist-deploy: devdeps dist
@echo "===> Uploading artifacts to https://cdn.kmkfw.io/"
@$(PIPENV) run s3cmd -c .s3cfg put dist/$(DIST_DESCRIBE).zip dist/$(DIST_DESCRIBE).unoptimized.zip s3://kmk-releases/ >/dev/null
@[[ "$${CIRCLE_BRANCH}" == "master" ]] && echo "====> Uploading artifacts as 'latest' to https://cdn.kmkfw.io/" || true
@[[ "$${CIRCLE_BRANCH}" == "master" ]] && $(PIPENV) run s3cmd -c .s3cfg put dist/latest.zip dist/latest.unoptimized.zip s3://kmk-releases/ >/dev/null || true
@[[ -n "$${CIRCLE_TAG}" ]] && echo "====> Uploading artifacts as '$${CIRCLE_TAG}' to https://cdn.kmkfw.io/" || true
@[[ -n "$${CIRCLE_TAG}" ]] && $(PIPENV) run s3cmd -c .s3cfg put dist/latest.zip s3://kmk-releases/$${CIRCLE_TAG}.zip >/dev/null || true
@[[ -n "$${CIRCLE_TAG}" ]] && $(PIPENV) run s3cmd -c .s3cfg put dist/latest.unoptimized.zip s3://kmk-releases/$${CIRCLE_TAG}.unoptimized.zip >/dev/null || true

dist/latest.zip: compile
@echo "===> Building optimized ZIP"
@mkdir -p dist
@cd $(MPY_TARGET_DIR) && zip -r ../dist/latest.zip kmk
@cd $(MPY_TARGET_DIR) && zip -r ../dist/latest.zip kmk 2>&1 >/dev/null

dist/$(shell $(DIST_DESCRIBE_CMD)).zip: dist/latest.zip
@cp dist/latest.zip dist/$$($(DIST_DESCRIBE_CMD)).zip
dist/$(DIST_DESCRIBE).zip: dist/latest.zip
@echo "===> Aliasing optimized ZIP"
@cp dist/latest.zip dist/$(DIST_DESCRIBE).zip

dist/latest.unoptimized.zip:
dist/latest.unoptimized.zip: $(PY_KMK_TREE)
@echo "===> Building unoptimized ZIP"
@mkdir -p dist
@zip -r dist/latest.unoptimized.zip kmk
@zip -r dist/latest.unoptimized.zip kmk 2>&1 >/dev/null

dist/$(shell $(DIST_DESCRIBE_CMD)).unoptimized.zip: dist/latest.unoptimized.zip
@cp dist/latest.unoptimized.zip dist/$$($(DIST_DESCRIBE_CMD)).unoptimized.zip
dist/$(DIST_DESCRIBE).unoptimized.zip: dist/latest.unoptimized.zip
@echo "===> Aliasing unoptimized ZIP"
@cp dist/latest.unoptimized.zip dist/$(DIST_DESCRIBE).unoptimized.zip

.docker_base: Dockerfile
@echo "===> Building Docker base image kmkfw/base:${DOCKER_BASE_TAG}"
Expand All @@ -63,7 +79,7 @@ docker-base-deploy: docker-base

.devdeps: Pipfile.lock
@echo "===> Installing dependencies with pipenv"
@$(PIPENV) install --dev --ignore-pipfile
@$(PIPENV) sync --dev
@touch .devdeps

devdeps: .devdeps
Expand All @@ -74,14 +90,10 @@ lint: devdeps
fix-isort: devdeps
@find kmk/ tests/ user_keymaps/ -name "*.py" | xargs $(PIPENV) run isort

clean: clean-build-log
clean:
@echo "===> Cleaning build artifacts"
@rm -rf .devdeps build dist $(MPY_TARGET_DIR)

clean-build-log:
@echo "===> Clearing previous .build.log"
@rm -rf .build.log

# This is mostly a leftover from the days we vendored stuff from
# micropython-lib via submodules. Leaving this here mostly in case someone goes
# exploring through the history of KMK's repo and manages to screw up their
Expand Down
13 changes: 7 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ verify_ssl = true
name = "pypi"

[packages]
pydux = "*"

[dev-packages]
adafruit-ampy = "*"
"flake8" = "*"
"flake8-commas" = "*"
"flake8-comprehensions" = "*"
ipython = "*"
"flake8-isort" = "*"
"flake8-per-file-ignores" = "*"
"python-magic" = "*"
adafruit-ampy = "*"
ipdb = "*"
"flake8-commas" = "*"
ipython = "*"
isort = "*"
"flake8-isort" = "*"
neovim = "*"
"flake8-per-file-ignores" = "*"
s3cmd = "*"

[requires]
python_version = "3.7"
36 changes: 25 additions & 11 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39e3a65

Please sign in to comment.