Skip to content

Upload to ali oss #5

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

Merged
merged 2 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ build: &build

deploy: &deploy
docker:
- image: tsub/ghr:latest
- image: broooooklyn/rust-python:latest
working_directory: /mnt/crate
steps:
- attach_workspace:
Expand All @@ -43,7 +43,8 @@ deploy: &deploy
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
then
export GIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"; \
ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so
ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so && \
python upload-ali-oss.py
else
echo "Not a release, skipping publish"
fi
Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ deploy:
skip_cleanup: true
on:
tags: true

deploy:
provider: script
script: python upload-ali-oss.py
on:
tags: true
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM ubuntu:18.04

ARG PYTHON_VERSION=3.6

ENV GHR_VERSION="0.9.0"

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
Expand All @@ -18,11 +20,19 @@ RUN apt-get update && \
if [ $PYTHON_VERSION = '3.6' ]; \
then \
apt-get install python3-pip -y --no-install-recommends && \
ln -sf /usr/bin/pip3 /usr/bin/pip; \
ln -sf /usr/bin/pip3 /usr/bin/pip && \
pip install setuptools; \
else \
curl https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION}; \
fi && \
pip install --upgrade pip
pip install --upgrade pip && \
curl -fSL -o ghr.tar.gz "https://github.com/tcnksm/ghr/releases/download/v${GHR_VERSION}/ghr_v${GHR_VERSION}_linux_amd64.tar.gz" && \
tar -xvzf ghr.tar.gz && \
mv ghr_v${GHR_VERSION}_linux_amd64/ghr /usr/local/bin && \
chown root:root /usr/local/bin/ghr && \
rm -r \
ghr.tar.gz \
ghr_v${GHR_VERSION}_linux_amd64

RUN set -eux; \
dpkgArch="$(dpkg --print-architecture)"; \
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ artifacts:
- path: build\lib\py_sourcemap\*.pyd
name: Binary

before_deploy:
- "%PYTHON%\\python.exe upload-ali-oss.py"

deploy:
provider: GitHub
description: $(APPVEYOR_REPO_TAG_NAME)
Expand Down
2 changes: 2 additions & 0 deletions requirement-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ yapf==0.23.0
twine==1.11.0
bumpversion==0.5.3
pytest==3.7.4
oss2==2.5.0
pycryptodome==3.6.6
37 changes: 37 additions & 0 deletions upload-ali-oss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys
import ntpath
import glob
import configparser

import oss2

endpoint = 'http://{region}.aliyuncs.com'.format(region='oss-cn-shanghai')

bucket_name = 'lc-frontend'

if __name__ == '__main__':
if len(sys.argv) >= 2:
files = sys.argv[1:]
else:
files = glob.glob('build/lib/py_sourcemap/*.so')

config = configparser.ConfigParser()
config.read('.bumpversion.cfg')
package_version = config['bumpversion']['current_version']

access_key = os.environ.get('ALIYUN_ACCESS_KEY')
access_token = os.environ.get('ALIYUN_ACCESS_TOKEN')

auth = oss2.Auth(access_key, access_token)
bucket = oss2.Bucket(auth, endpoint, bucket_name)

for file_path in files:
basename = ntpath.basename(file_path)
fp = open(file_path, 'rb')
target_key = 'packages/py_sourcemap/{version}/{name}'.format(
version=package_version, name=basename)
print('Uploading {}...'.format(target_key))
bucket.put_object(target_key, fp.read())
fp.close()
print('Uploaded all.')