-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (80 loc) · 3.13 KB
/
docker-prod-push.yml
File metadata and controls
94 lines (80 loc) · 3.13 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Docker Production Build & Push
on:
workflow_run:
workflows: ["Dockerfiles Quality Check"]
types:
- completed
branches: [main, master]
workflow_dispatch:
concurrency:
group: docker-prod-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build-and-push:
name: Build and Push Production Image
runs-on: self-hosted # ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/thesis-app
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.title=Thesis Defense Scheduling System
org.opencontainers.image.description=Complete application for thesis defense scheduling with PostgreSQL, Python API, and Nginx in single container
org.opencontainers.image.vendor=WinterWollf
org.opencontainers.image.source=https://github.com/WinterWollf/Engineering-thesis
- name: Build base images for production
run: |
echo "Building base images required for Dockerfile.prod..."
docker build -f Dockerfile.api -t engineering-thesis-api:latest .
docker build -f Dockerfile.nginx -t engineering-thesis-nginx:latest .
echo "Base images built successfully"
- name: Build production image
run: |
echo "Building production image using local base images..."
docker build -f Dockerfile.prod -t temp-prod-image .
echo "Production image built successfully"
- name: Tag and push production image
run: |
echo "Tagging and pushing production image..."
# Parse tags from metadata step
TAGS="${{ steps.meta.outputs.tags }}"
LABELS="${{ steps.meta.outputs.labels }}"
# Tag and push each tag
echo "$TAGS" | while IFS= read -r tag; do
if [ -n "$tag" ]; then
echo "Tagging as: $tag"
docker tag temp-prod-image "$tag"
echo "Pushing: $tag"
docker push "$tag"
fi
done
echo "All tags pushed successfully"
- name: Show pushed image info
run: |
echo "Successfully pushed image with tags:"
echo "${{ steps.meta.outputs.tags }}"
echo ""
echo "Image labels:"
echo "${{ steps.meta.outputs.labels }}"
echo ""
echo "Pull command for latest:"
echo "docker pull ${{ secrets.DOCKER_USERNAME }}/thesis-app:latest"