diff --git a/bin/push-readme.py b/bin/push-readme.py new file mode 100644 index 0000000..e4fd067 --- /dev/null +++ b/bin/push-readme.py @@ -0,0 +1,32 @@ +import logging +import os + +import requests + + +logging.basicConfig(level=logging.INFO) + + +DOCKER_REPO = os.environ.get('DOCKER_REPO') +DOCKER_USERNAME = os.environ.get('DOCKER_USERNAME') +DOCKER_PASSWORD = os.environ.get('DOCKER_PASSWORD') +README_FILE = os.environ.get('README_FILE') or 'README.md' + + +logging.info('Generating Docker Hub JWT') +data = {'username': DOCKER_USERNAME, 'password': DOCKER_PASSWORD} +r = requests.post('https://hub.docker.com/v2/users/login/', json=data) +docker_token = r.json().get('token') + +logging.info(f'Updating Docker Hub description for {DOCKER_REPO}') +with open(README_FILE) as f: + full_description = f.read() +data = {'registry': 'registry-1.docker.io', 'full_description': full_description} +headers = {'Authorization': f'JWT {docker_token}'} +r = requests.patch(f'https://cloud.docker.com/v2/repositories/{DOCKER_REPO}/', + json=data, headers=headers) + +if r.status_code == requests.codes.ok: + logging.info(f'Successfully updated {README_FILE} for {DOCKER_REPO}') +else: + logging.info(f'Unable to update {README_FILE} for {DOCKER_REPO}, response code: {r.status_code}') \ No newline at end of file diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index ac487c7..3a7ade1 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -53,7 +53,7 @@ pipelines: script: - echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin - > - docker build -t atlassian/confluence-server:${DOCKER_TAG} + docker build -t atlassian/confluence-server:${DOCKER_TAG} -f Dockerfile-alpine --build-arg CONFLUENCE_VERSION=${CONFLUENCE_VERSION} . - docker push atlassian/confluence-server:${DOCKER_TAG} @@ -86,6 +86,13 @@ pipelines: - export TAG_SUFFIXES='adoptopenjdk8,jdk8,ubuntu,ubuntu-18.04-adoptopenjdk8' - echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin - python /usr/src/app/run.py --update + - step: + name: Update README + image: python:3.7-alpine3.9 + script: + - pip install -q requests + - export DOCKER_REPO='atlassian/confluence-server' + - python bin/push-readme.py pull-requests: '**': - step: @@ -98,4 +105,4 @@ pipelines: definitions: services: docker: - memory: 2048 \ No newline at end of file + memory: 2048