Skip to content

Commit bd4a8cb

Browse files
Added CI pipeline hamzaavvan#11
1 parent b637a55 commit bd4a8cb

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,36 @@ jobs:
1919
sudo apt-get update
2020
sudo apt-get install -y docker-compose
2121
22-
# 3️⃣ Login to Docker Hub
22+
# 3️⃣ Create .env file (needed by app service)
23+
- name: Create .env file
24+
run: |
25+
echo "FLASK_ENV=production" >> .env
26+
echo "DB_USER=lmsuser" >> .env
27+
echo "DB_PASSWORD=lms123" >> .env
28+
echo "DB_NAME=lms" >> .env
29+
echo "DB_PORT=3306" >> .env
30+
echo "MYSQL_HOST=mysql" >> .env
31+
32+
# 4️⃣ Login to Docker Hub
2333
- name: Login to Docker Hub
2434
run: |
2535
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
2636
27-
# ✅ Add .env file before build
28-
- name: Create .env file
29-
run: |
30-
echo "DB_USER=root" >> .env
31-
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
32-
echo "DB_NAME=library" >> .env
33-
34-
# 4️⃣ Build all images from docker-compose
37+
# 5️⃣ Build Docker images from docker-compose
3538
- name: Build Docker images
3639
run: |
3740
docker-compose build
3841
39-
# 5️⃣ Tag and push all images with `latest` and `v2`
42+
# 6️⃣ Tag and Push both app & mysql images
4043
- name: Tag and Push images
4144
run: |
42-
# List all built images
43-
docker images
44-
45-
# Loop through each service defined in docker-compose
4645
for service in $(docker-compose config --services); do
4746
IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/${service}
48-
4947
echo "Tagging and pushing $IMAGE_NAME ..."
5048
51-
# Tag images
5249
docker tag ${service}:latest $IMAGE_NAME:latest
5350
docker tag ${service}:latest $IMAGE_NAME:v2
5451
55-
# Push both tags
5652
docker push $IMAGE_NAME:latest
5753
docker push $IMAGE_NAME:v2
5854
done

0 commit comments

Comments
 (0)