Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment to dockerhub #65

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,64 @@ jobs:
- name: Run frontend tests
run: cd frontend && npm run test

backend-build:
runs-on: ubuntu-latest

backend-build-and-deploy-multi-arch:
runs-on: ubuntu-latest # Use an Ubuntu runner
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Checkout the repository to access the Dockerfile and source code
- name: Checkout code
uses: actions/checkout@v3

- name: Build backend Docker container
working-directory: api
run: |
docker build -t api .
# Set up Docker Buildx (needed for multi-platform builds)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

frontend-build:
runs-on: ubuntu-latest
# Log in to DockerHub using secrets (replace with your DockerHub credentials)
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: "fit3162"
password: 'Gzg[8s!xS=w"<W7;ag3A'

# Build and push the Docker image for multiple platforms (AMD64, ARM)
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./api # The root directory, assuming your Dockerfile is here
platforms: linux/amd64,linux/arm64 # Build for AMD64 and ARM64
push: true # Push the image to DockerHub after building
tags: |
fit3162/backend:latest
fit3162/backend:${{ github.sha }}



frontend-build-and-deploy-multi-arch:
runs-on: ubuntu-latest # Use an Ubuntu runner

steps:
- name: Checkout repository
uses: actions/checkout@v2
# Checkout the repository to access the Dockerfile and source code
- name: Checkout code
uses: actions/checkout@v3

- name: Build frontend Docker container
working-directory: frontend
run: |
docker build -t frontend .
# Set up Docker Buildx (needed for multi-platform builds)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Log in to DockerHub using secrets (replace with your DockerHub credentials)
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: "fit3162"
password: 'Gzg[8s!xS=w"<W7;ag3A'

# Build and push the Docker image for multiple platforms (AMD64, ARM)
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./frontend # The root directory, assuming your Dockerfile is here
platforms: linux/amd64,linux/arm64 # Build for AMD64 and ARM64
push: true # Push the image to DockerHub after building
tags: |
fit3162/frontend:latest
fit3162/frontend:${{ github.sha }}
29 changes: 29 additions & 0 deletions docker-compose.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
postgres:
image: "postgres:latest"
environment:
POSTGRES_DB: mydatabase
POSTGRES_PASSWORD: password
POSTGRES_USER: myuser
ports:
- "5432:5432"

backend:
image: "fit3162/backend:latest"
ports:
- "8080:8080"
depends_on:
- postgres
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/mydatabase
SPRING_DATASOURCE_USERNAME: myuser
SPRING_DATASOURCE_PASSWORD: password
LOGGING_LEVEL_ROOT: "info"
SERVER_PORT: 8080

frontend:
image: "fit3162/frontend:latest"
depends_on:
- backend
ports:
- "80:80"
2 changes: 1 addition & 1 deletion scripts/cleanup-all-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
docker compose -f docker-compose.fullstack.yml down -v
docker compose -f docker-compose.frontend-dev-mode.yml down -v
docker compose -f docker-compose.backend-only.yml down -v
docker compose -f docker-compose.deploy.yml down -v

# Optionally, remove dangling volumes not associated with any container
docker volume prune -f
3 changes: 3 additions & 0 deletions scripts/deploy-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker compose -f docker-compose.deploy.yml up --force-recreate -d
Loading