-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (112 loc) · 4.08 KB
/
build-and-push.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Build and Push to GHCR
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
packages: write # Allows pushing to GHCR
contents: read # Allows reading the repository content
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Official Image
uses: docker/build-push-action@v6
with:
context: ./examples/official
file: ./examples/official/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64
tags: |
ghcr.io/${{ github.repository_owner }}/uv-official:latest
ghcr.io/${{ github.repository_owner }}/uv-official:${{ github.sha }}
cache-from: type=gha,scope=uv-official
cache-to: type=gha,mode=min,scope=uv-official
outputs: |
type=registry,push=true
type=docker,dest=/tmp/uv-official.tar
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.description=Official UV Docker Example
org.opencontainers.image.licenses=MIT
- name: Build and Push Custom Image
uses: docker/build-push-action@v6
with:
context: ./examples/custom
file: ./examples/custom/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64
tags: |
ghcr.io/${{ github.repository_owner }}/uv-custom:latest
ghcr.io/${{ github.repository_owner }}/uv-custom:${{ github.sha }}
cache-from: type=gha,scope=uv-custom
cache-to: type=gha,mode=min,scope=uv-custom
outputs: |
type=registry,push=true
type=docker,dest=/tmp/uv-custom.tar
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.description=Custom UV Docker Example
org.opencontainers.image.licenses=MIT
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: docker-images
path: /tmp/*.tar
test:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docker-images
path: /tmp
- name: Load images
run: |
docker load --input /tmp/uv-official.tar
docker load --input /tmp/uv-custom.tar
docker image ls -a
- name: Create test compose file
run: |
cat > docker-compose.test.yml << EOF
services:
official:
image: ghcr.io/loftwah/uv-official:latest
ports:
- "8000:8000"
custom:
image: ghcr.io/loftwah/uv-custom:latest
ports:
- "8001:8000"
EOF
- name: Test Images
run: |
docker compose -f docker-compose.test.yml up -d
echo "Waiting for services to start..."
sleep 10
echo "Checking containers status..."
docker ps
echo "Checking container logs..."
docker compose -f docker-compose.test.yml logs
echo "Testing official service..."
curl -v http://localhost:8000
echo "Testing custom service..."
curl -v http://localhost:8001
docker compose -f docker-compose.test.yml down