diff --git a/.env.example b/.env.example index 9983df70..f7ed5938 100644 --- a/.env.example +++ b/.env.example @@ -16,4 +16,6 @@ AUTH0_CALLBACK_URL=http://localhost:3000/callback SENDGRID_API_KEY=123456 BASE_URL=http://localhost:3000 HASURA_JWT_SECRET= -GRAPHQL_SERVER_URI=http://localhost:5000 \ No newline at end of file +GRAPHQL_SERVER_URI=http://localhost:5000 +SPACES_KEY_ID= +SPACES_SECRET_ACCESS_KEY= \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3dc64cd1..a3fa2088 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -243,6 +243,23 @@ deploy_review_hasura: - kubectl rollout status -f /tmp/deployment.yaml - kubectl get deploy,svc,ing,pod -l app="$(echo ${CI_PROJECT_NAME} | tr "." "-")",ref="${CI_ENVIRONMENT_SLUG}" +upload_to_cdn: + image: + name: python:latest + entrypoint: ['/bin/sh', '-c'] + stage: 'Deploy' + environment: + name: production + url: https://gameofblocks.io + only: + - master + before_script: + - pip install boto3 + script: + - cd .gitlab/ci + - echo $SPACES_KEY_ID + - python spaces-uploader.py + ############### Stop APP ############################### stop_review: diff --git a/.gitlab/ci/spaces-uploader.py b/.gitlab/ci/spaces-uploader.py new file mode 100644 index 00000000..28af0349 --- /dev/null +++ b/.gitlab/ci/spaces-uploader.py @@ -0,0 +1,40 @@ +# https://medium.com/@brianobilo/uploading-files-to-digital-ocean-spaces-using-api-keys-and-boto3-1f24242f6cd7 +import os +from os import walk +import boto3 +from boto3 import session +from botocore.client import Config +from boto3.s3.transfer import S3Transfer + +public_folder_path = '../../packages/app/public' + +files = [] +# r=root, d=directories, f = files +for r, d, f in os.walk(public_folder_path): + print(d) + for file in f: + files.append(os.path.join(r, file)) + +#Use the API Keys you generated at Digital Ocean +ACCESS_ID = os.environ['SPACES_KEY_ID'] +SECRET_KEY = os.environ['SPACES_SECRET_ACCESS_KEY'] + +# Initiate session +session = session.Session() +client = session.client('s3', + region_name='sfo2', + endpoint_url='https://sfo2.digitaloceanspaces.com', + aws_access_key_id=ACCESS_ID, + aws_secret_access_key=SECRET_KEY) + +transfer = S3Transfer(client) +name_of_space = "assets.gameofblocks" + +for f in files: + file_to_import = f[(len(public_folder_path) + 1):len(f)] + print(file_to_import) + transfer.upload_file(f, name_of_space, file_to_import) + # This makes the file you are have specifically uploaded public by default. + response = client.put_object_acl(ACL='public-read', Bucket=name_of_space, Key=file_to_import) + +print(len(files) + " files uploaded") \ No newline at end of file diff --git a/packages/app/public/images/throne.jpg b/packages/app/public/images/throne.jpg new file mode 100644 index 00000000..02263a4c Binary files /dev/null and b/packages/app/public/images/throne.jpg differ