Skip to content

Build and Publish Docker image to Docker Hub #3

Build and Publish Docker image to Docker Hub

Build and Publish Docker image to Docker Hub #3

Workflow file for this run

name: Build and Publish Docker image to Docker Hub
on:
push:
branches:
- main
paths:
- 'backend/library/Dcokerfile'
- 'frontend/Dockerfile'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: temadeveloper
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# ---- Build and push the backend image ----
- name: build the Docker image
run: docker build ./backend/library/ -t temadeveloper/library_proj:latest
- name: push image
run: |
docker push temadeveloper/library_proj:latest
# ---- Build and push the frontend image ----
- name: Build the frontend Docker image
# Assumes your frontend Dockerfile is in the 'frontend' directory
run: docker build ./frontend/ -t temadeveloper/library_proj_frontend:latest
- name: Push frontend image
run: |
docker push temadeveloper/library_proj_frontend:latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: './frontend/package-lock.json'
- name: Install dependencies
run: npm install
working-directory: ./frontend
- name: Build Next.js app
run: npm run build
working-directory: ./frontend
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@v3
with:
path: './frontend/out'
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4