From 62575674b40d55e885b579e72985d9a5d0de3a7a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 17 May 2024 11:41:04 +0200 Subject: [PATCH] Remove WORKSPACE from s3 image path --- .github/workflows/deploy.yml | 98 ------------------------------------ .github/workflows/pr.yml | 1 - Makefile | 8 +-- backend/src/config.py | 2 +- backend/src/utils.py | 4 +- backend/tests/test_api.py | 3 +- docker-compose.yml | 1 - 7 files changed, 5 insertions(+), 112 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index f73f8b7f..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,98 +0,0 @@ -on: - workflow_call: - inputs: - image_version: - required: false - type: string - description: "Docker image version to pull for deployment" - default: "latest" - branch: - required: false - description: "Branch to pull in instance deployment" - type: string - default: "main" - volume_size: - required: false - description: "Size in GB of instance" - type: number - default: 10 - flavor: - required: false - type: string - description: "Flavor of instance" - default: "s1-2" - workspace: - required: true - type: string - description: "Workspace used for deployment: prod or preprod" - default: "prod" - secrets: - API_OVH_TOKEN: - required: true - SERVER_IP: - required: true - OS_PASSWORD: - required: true - OS_PROJECT_ID: - required: true - OS_PROJECT_NAME: - required: true - OS_USERNAME: - required: true - X_OVH_TOKEN: - required: true -jobs: - deployment: - name: Deployment - runs-on: ubuntu-20.04 - defaults: - run: - working-directory: ./infra/terraform - env: - API_OVH_TOKEN: ${{ secrets.API_OVH_TOKEN }} - APP_BRANCH: ${{ inputs.branch }} - APP_VERSION: ${{ inputs.image_version }} - OS_AUTH_URL: https://auth.cloud.ovh.net/v3 - OS_IDENTITY_API_VERSION: 3 - OS_INTERFACE: public - OS_PASSWORD: ${{ secrets.OS_PASSWORD }} - OS_PROJECT_NAME: ${{ secrets.OS_PROJECT_NAME }} - OS_PROJECT_ID: ${{ secrets.OS_PROJECT_ID }} - OS_REGION_NAME: "GRA7" - OS_USER_DOMAIN_NAME: "Default" - OS_USERNAME: ${{ secrets.OS_USERNAME }} - TF_VAR_fixed_ip: ${{ secrets.SERVER_IP }} - TF_VAR_flavor: ${{ inputs.flavor }} - TF_VAR_volume_size: ${{ inputs.volume_size }} - WORKSPACE: ${{ inputs.workspace }} - X_OVH_TOKEN: ${{ secrets.X_OVH_TOKEN }} - - steps: - - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: 1.1.8 - - - uses: actions/checkout@v2 - - name: Terraform Init - id: init - run: terraform init - - - name: Terraform Validate - id: validate - run: terraform validate -no-color - - - name: Terraform Workspace - run: terraform workspace select ${WORKSPACE} || terraform workspace new ${WORKSPACE} - - - name: Terraform Taint if exist - run: terraform taint -allow-missing openstack_compute_instance_v2.instance - - - name: Terraform apply - run: | - envsubst < env.tfvars > deployenv.tfvars - terraform apply --auto-approve -var-file="deployenv.tfvars" - -#TODO: -#use if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' -#or on: push -#TODO: run script if server is reachable diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 51d53f7b..a26623c6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -62,7 +62,6 @@ jobs: container: image: ghcr.io/datalab-mi/basegun/basegun-backend:${{ github.head_ref }} env: - WORKSPACE: dev AWS_REGION: gra AWS_DEFAULT_REGION: gra AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} diff --git a/Makefile b/Makefile index 7e1ddb1e..beed764e 100644 --- a/Makefile +++ b/Makefile @@ -29,14 +29,10 @@ check-dc-config-%: check-prerequisites ## Check docker-compose syntax ${DC} config -q build: check-dc-config-% - TAG=${TAG} ${DC} build + ${DC} build up: check-dc-config-% -ifeq ("$(WORKSPACE)","preprod") - TAG=${TAG} PORT_PROD=8080 ${DC} up -d -else - TAG=${TAG} ${DC} up -d -endif + ${DC} up -d down: ${DC} down diff --git a/backend/src/config.py b/backend/src/config.py index b3d9674b..2edcc82d 100644 --- a/backend/src/config.py +++ b/backend/src/config.py @@ -105,7 +105,7 @@ def get_base_logs(user_agent, user_id: str) -> dict: # Object storage S3_URL_ENDPOINT = os.environ["S3_URL_ENDPOINT"] S3_BUCKET_NAME = os.environ["S3_BUCKET_NAME"] -S3_PREFIX = os.path.join("uploaded-images/", os.environ["WORKSPACE"]) +S3_PREFIX = os.path.join("uploaded-images/") S3 = boto3.resource("s3", endpoint_url=S3_URL_ENDPOINT, verify=False) diff --git a/backend/src/utils.py b/backend/src/utils.py index fb0460fc..8ac2eaa5 100644 --- a/backend/src/utils.py +++ b/backend/src/utils.py @@ -7,9 +7,7 @@ def upload_image(content: bytes, image_key: str): """Uploads an image to s3 bucket - path uploaded-images/WORKSPACE/img_name - where WORKSPACE is dev, preprod or prod - + path uploaded-images/img_name Args: content (bytes): file content image_key (str): path we want to have diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index d25525a2..31430a79 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -66,8 +66,7 @@ def check_log_base(self, log): def test_upload(self): """Checks that the file upload works properly""" - if os.environ["WORKSPACE"] == "dev": - create_bucket() + create_bucket() path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "revolver.jpg") with open(path, "rb") as f: diff --git a/docker-compose.yml b/docker-compose.yml index 99337d1b..4769b4ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,6 @@ services: - http_proxy - https_proxy - no_proxy - - WORKSPACE=dev - REQUESTS_CA_BUNDLE=$CACERT_LOCATION ports: - 5000:5000