Skip to content

Commit

Permalink
chore: Better image building
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-castro committed Nov 9, 2024
1 parent 73f0613 commit 06733de
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 187 deletions.
4 changes: 1 addition & 3 deletions .env.exemple
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/build-and-push-dev.yml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions .github/workflows/build-and-push-prod.yml
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -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 }}
44 changes: 0 additions & 44 deletions .github/workflows/staging-backend.dev.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/staging-backend.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/staging-frontend.dev.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/staging-frontend.yml

This file was deleted.

5 changes: 1 addition & 4 deletions backend/src/config/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/integration/.env.integration
Original file line number Diff line number Diff line change
Expand Up @@ -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
STRIPE_SECRET_KEY=sk_test_123
4 changes: 2 additions & 2 deletions e2e/.env.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -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
STRIPE_SECRET_KEY=sk_test_123

0 comments on commit 06733de

Please sign in to comment.