-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (47 loc) · 2.68 KB
/
docker-ci.yml
File metadata and controls
57 lines (47 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -----------------------------------------------------------------------------
# 📦 GitHub Actions: docker-ci.yml
# Purpose: Automatically build and publish Docker images
# on every push to the `main` branch.
# This is a CI/CD workflow (Continuous Integration & Delivery).
#
# What it does:
# 1. Clones the project code.
# 2. Logs into Docker Hub.
# 3. Builds backend and frontend Docker images.
# 4. Pushes these images to Docker Hub.
# -----------------------------------------------------------------------------
name: Docker CI # Workflow name shown on GitHub
on:
push:
branches: [ main ] # 👉 Run only when pushing to the "main" branch
jobs:
build: # 👷 Job name
runs-on: ubuntu-latest # 🔧 GitHub Actions will run on an Ubuntu VM
steps: # 📋 Steps executed sequentially
- name: Checkout code # 🧾 Step 1: Clone the repository
uses: actions/checkout@v3 # 📥 Official GitHub checkout action
- name: Set up Docker Buildx # 🧰 Step 2: Setup Buildx — Docker extension for advanced builds
uses: docker/setup-buildx-action@v3 # 📦 Action to install buildx
- name: Login to Docker Hub # 🔐 Step 3: Authenticate to Docker Hub to push images
uses: docker/login-action@v3 # 🛂 Official login method
with:
username: ${{ secrets.DOCKER_USERNAME }} # 🔒 Username from GitHub secrets
password: ${{ secrets.DOCKER_PASSWORD }} # 🔒 Password or token from secrets (secure)
- name: Build and push backend # ⚙️ Step 4: Build and push backend image
uses: docker/build-push-action@v5 # 🛠️ Build and push Docker images
with:
context: ./backend # 📁 Build context — backend folder
tags: ${{ secrets.DOCKER_USERNAME }}/flask-api:latest # 🏷️ Image name: dockerhub_user/flask-api
push: true # 📤 Push the image after build
- name: Build and push frontend # ⚙️ Step 5: Build and push frontend image
uses: docker/build-push-action@v5 # 🛠️ Same as above, for frontend
with:
context: ./frontend # 📁 Build context — frontend folder
tags: ${{ secrets.DOCKER_USERNAME }}/node-frontend:latest # 🏷️ Image name: dockerhub_user/node-frontend
push: true # 📤 Push the image to Docker Hub
- name: Build and push nginx # ⚙️ Step 6: Build and push nginx image
uses: docker/build-push-action@v5 # 🛠️ Same, for nginx
with:
context: ./nginx # 📁 Build context — nginx folder
tags: ${{ secrets.DOCKER_USERNAME }}/nginx:latest # 🏷️ Image name: dockerhub_user/nginx
push: true # 📤 Push the image to Docker Hub