Skip to content

Commit

Permalink
Merge pull request #20 from KPMP/develop
Browse files Browse the repository at this point in the history
Atlas 2024 Q3 Release
  • Loading branch information
zwright authored Oct 2, 2024
2 parents 50f5ee1 + 90d5390 commit 2bd87f6
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.*
39 changes: 39 additions & 0 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build atlas-file-service docker image

on:
push:

jobs:
build-project:
env:
IMAGE_TAG: 3.4
runs-on: ubuntu-latest
steps:
- name: Get branch names
id: branch-names
uses: tj-actions/branch-names@v8

- name: Get current branch name
if: steps.branch-names.outputs.is_default == 'false'
run: |
echo "Running on branch: ${{ steps.branch-names.outputs.current_branch }}"
- name: Login to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.ENV_DOCKER_USER }}
password: ${{ secrets.ENV_DOCKER_PASS }}

- name: Build and push to Docker Hub if branch is develop
if: steps.branch-names.outputs.current_branch == 'develop'
uses: docker/build-push-action@v5
with:
push: true
tags: kingstonduo/atlas-file-service:${{ env.IMAGE_TAG }}

- name: Build and push to Docker Hub if branch is not develop
if: steps.branch-names.outputs.current_branch != 'develop'
uses: docker/build-push-action@v5
with:
push: true
tags: kingstonduo/atlas-file-service:${{ steps.branch-names.outputs.current_branch }}
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM python:3.7.12-alpine3.14
WORKDIR /code
ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers tzdata libffi-dev libc-dev
COPY app.py app.py
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN pip3 install -U flask-cors
CMD ["flask", "run"]
CMD ["gunicorn", "-b", ":5000", "app:app"]
27 changes: 22 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from flask_cors import CORS
import mysql.connector
import logging
import requests
import json

app = Flask(__name__)
CORS(app)
Expand All @@ -15,6 +17,9 @@
minioSecretKey = os.environ.get('MINIO_SECRET_KEY')
s3Bucket = os.environ.get('BUCKET_NAME')
minioUrl = os.environ.get('MINIO_URL')
apiSecret = os.environ.get("API_SECRET")
ga4Id = os.environ.get("GA4_ID")
url = "https://www.google-analytics.com/mp/collect?measurement_id=" + ga4Id + "&api_secret=" + apiSecret
minioClient = Minio(minioUrl, access_key=minioAccessKey, secret_key=minioSecretKey, secure=False)
s3_client = boto3.client(
's3',
Expand All @@ -29,7 +34,7 @@

class MYSQLConnection:
def __init__(self):
logger.debug(
logger.info(
"Start: MYSQLConnection().__init__(), trying to load environment variables in docker"
)
self.host = None
Expand Down Expand Up @@ -103,14 +108,26 @@ def get_file_info_by_file_name(file_name):
(file_name,),
)


@app.route('/v1/file/download/<packageId>/<objectName>', methods=['GET'])
@app.route('/v1/file/download/<packageId>/<objectName>', methods=['POST', 'GET'])
def downloadFile(packageId, objectName):
result = get_file_info_by_file_name(objectName)
if result[0]["access"] == "open":
try:
objectNameFull = packageId + '/' + objectName
object = minioClient.get_object(s3Bucket, objectNameFull, request_headers=None)
payload = {
"client_id": "XXXXXXXXXX.YYYYYYYYYY",
"events": [
{
"name": "AtlasRepositoryDownload",
"params": {
"event_category": "Repository",
"event_action": "Download",
"label": objectName
}
}]
}
requests.post(url, json=payload, headers={"Content-Type": "application/json"})
return send_file(object, as_attachment=True, download_name=objectName)
except S3Error as err:
logger.error(err)
Expand All @@ -127,6 +144,6 @@ def downloadDerivedFileS3PS(packageId, objectName):
Params={'Bucket': s3Bucket, 'Key': objectNameFull},
ExpiresIn=3600)
except botocore.exceptions.ClientError as error:
logger.error(err)
logger.error(error)
except botocore.exceptions.ParamValidationError as error:
logger.error(err)
logger.error(error)
14 changes: 14 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

## Release 1.4 [unreleased]
Brief summary of what's in this release:


### Breaking changes

Breaking changes include any database updates needed, if we need to edit any files on system (like .env or certs, etc). Things that are outside of the code itself that need changed for the system to work.


### Non-breaking changes

Just a place to keep track of things that have changed in the code that we may want to pay special attention to when smoke testing, etc.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ minio
boto3
flask-cors
mysql-connector-python
requests
gunicorn

0 comments on commit 2bd87f6

Please sign in to comment.