diff --git a/.env.exemple b/.env.exemple index e32133f..25c3745 100644 --- a/.env.exemple +++ b/.env.exemple @@ -1,9 +1,7 @@ JWT_SECRET_KEY=defaultvalue # The service name in docker-compose -DATABASE_HOST_PROD=db -DATABASE_HOST_DEV=db - +DATABASE_HOST=db DATABASE_PORT=5432 DATABASE_USERNAME=postgres DATABASE_PASSWORD=password diff --git a/.github/workflows/build-and-push-dev.yml b/.github/workflows/build-and-push-dev.yml new file mode 100644 index 0000000..1f5bbcf --- /dev/null +++ b/.github/workflows/build-and-push-dev.yml @@ -0,0 +1,14 @@ +name: Compile and push dev images + +on: + push: + branches: ["develop"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + uses: ./.github/workflows/reusable-workflow.yml + with: + environment: "dev" diff --git a/.github/workflows/build-and-push-prod.yml b/.github/workflows/build-and-push-prod.yml new file mode 100644 index 0000000..0131906 --- /dev/null +++ b/.github/workflows/build-and-push-prod.yml @@ -0,0 +1,14 @@ +name: Compile and push prod images + +on: + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + uses: ./.github/workflows/reusable-workflow.yml + with: + environment: "prod" diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 0000000..df70b6a --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,34 @@ +# .github/workflows/build-and-push.yml +name: Build and push + +on: + workflow_call: + inputs: + environment: + required: true + type: string + +jobs: + build-and-push-images: + strategy: + matrix: + service: [frontend, backend] + runs-on: ubuntu-latest + steps: + - name: Check inputs + if: ${{ inputs.environment != 'dev' && inputs.environment != 'prod' }} + run: echo "Wrong environment. Expected 'dev' or 'prod', got '${{ inputs.environment }}'" && exit 1 + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push backend image + run: | + docker build -t healthcheck-${{ matrix.service }}:${{ inputs.environment }} ${{ matrix.service }} + docker push healthcheck-${{ matrix.service }}:${{ inputs.environment }} diff --git a/.github/workflows/staging-backend.dev.yml b/.github/workflows/staging-backend.dev.yml deleted file mode 100644 index 115ccf9..0000000 --- a/.github/workflows/staging-backend.dev.yml +++ /dev/null @@ -1,44 +0,0 @@ -# .github/workflows/staging-backend.yml -name: Compile and push backend image - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: ["develop"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # login with Docker - - uses: docker/login-action@v1 - name: Login to Docker Hub - with: - # generate some credentials from Dockerhub and store them into the repo secrets - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # prepare buildx for docker - - uses: docker/setup-buildx-action@v1 - name: Set up Docker Buildx - - # build an push the newly created image - - uses: docker/build-push-action@v2 - name: Build and push - with: - context: ./backend - file: ./backend/Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_DEV_BACKEND_IMAGE_NAME }}:latest \ No newline at end of file diff --git a/.github/workflows/staging-backend.yml b/.github/workflows/staging-backend.yml deleted file mode 100644 index 97db95f..0000000 --- a/.github/workflows/staging-backend.yml +++ /dev/null @@ -1,44 +0,0 @@ -# .github/workflows/staging-backend.yml -name: Compile and push backend image - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # login with Docker - - uses: docker/login-action@v1 - name: Login to Docker Hub - with: - # generate some credentials from Dockerhub and store them into the repo secrets - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # prepare buildx for docker - - uses: docker/setup-buildx-action@v1 - name: Set up Docker Buildx - - # build an push the newly created image - - uses: docker/build-push-action@v2 - name: Build and push - with: - context: ./backend - file: ./backend/Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_BACKEND_IMAGE_NAME }}:latest \ No newline at end of file diff --git a/.github/workflows/staging-frontend.dev.yml b/.github/workflows/staging-frontend.dev.yml deleted file mode 100644 index 108c177..0000000 --- a/.github/workflows/staging-frontend.dev.yml +++ /dev/null @@ -1,44 +0,0 @@ -# .github/workflows/staging-frontend.yml -name: Compile and push client image - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: ["develop"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # login with Docker - - uses: docker/login-action@v1 - name: Login to Docker Hub - with: - # generate some credentials from Dockerhub and store them into the repo secrets - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # prepare buildx for docker - - uses: docker/setup-buildx-action@v1 - name: Set up Docker Buildx - - # build an push the newly created image - - uses: docker/build-push-action@v2 - name: Build and push - with: - context: ./frontend - file: ./frontend/Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_DEV_FRONTEND_IMAGE_NAME }}:latest \ No newline at end of file diff --git a/.github/workflows/staging-frontend.yml b/.github/workflows/staging-frontend.yml deleted file mode 100644 index 91b3c28..0000000 --- a/.github/workflows/staging-frontend.yml +++ /dev/null @@ -1,44 +0,0 @@ -# .github/workflows/staging-frontend.yml -name: Compile and push client image - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # login with Docker - - uses: docker/login-action@v1 - name: Login to Docker Hub - with: - # generate some credentials from Dockerhub and store them into the repo secrets - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # prepare buildx for docker - - uses: docker/setup-buildx-action@v1 - name: Set up Docker Buildx - - # build an push the newly created image - - uses: docker/build-push-action@v2 - name: Build and push - with: - context: ./frontend - file: ./frontend/Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_FRONTEND_IMAGE_NAME }}:latest \ No newline at end of file diff --git a/backend/src/config/db.ts b/backend/src/config/db.ts index 5f42a13..0a8ed7d 100644 --- a/backend/src/config/db.ts +++ b/backend/src/config/db.ts @@ -6,12 +6,9 @@ import * as dotenv from 'dotenv'; dotenv.config(); -const isProd = process.env.NODE_ENV === 'production'; -const databaseHost = isProd ? process.env.DATABASE_HOST_PROD : process.env.DATABASE_HOST_DEV; - export const dataSource = new DataSource({ type: "postgres", - host: databaseHost, + host: process.env.DATABASE_HOST, port: parseInt(process.env.DATABASE_PORT!), username: process.env.DATABASE_USERNAME, password: process.env.DATABASE_PASSWORD, diff --git a/backend/tests/integration/.env.integration b/backend/tests/integration/.env.integration index cd0e544..1db9f4c 100644 --- a/backend/tests/integration/.env.integration +++ b/backend/tests/integration/.env.integration @@ -3,10 +3,10 @@ NODE_ENV=production JWT_SECRET_KEY=defaultvalue # The service name in docker-compose -DATABASE_HOST_PROD=db +DATABASE_HOST=db DATABASE_PORT=5432 DATABASE_USERNAME=postgres DATABASE_PASSWORD=password DATABASE_NAME=postgres -STRIPE_SECRET_KEY=sk_test_123 \ No newline at end of file +STRIPE_SECRET_KEY=sk_test_123 diff --git a/e2e/.env.e2e b/e2e/.env.e2e index cd0e544..1db9f4c 100644 --- a/e2e/.env.e2e +++ b/e2e/.env.e2e @@ -3,10 +3,10 @@ NODE_ENV=production JWT_SECRET_KEY=defaultvalue # The service name in docker-compose -DATABASE_HOST_PROD=db +DATABASE_HOST=db DATABASE_PORT=5432 DATABASE_USERNAME=postgres DATABASE_PASSWORD=password DATABASE_NAME=postgres -STRIPE_SECRET_KEY=sk_test_123 \ No newline at end of file +STRIPE_SECRET_KEY=sk_test_123