-
Notifications
You must be signed in to change notification settings - Fork 198
208 lines (178 loc) 路 7.71 KB
/
Copy pathdocker-build-deploy.yml
File metadata and controls
208 lines (178 loc) 路 7.71 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Build and Deploy Docker Images
# on:
# push:
# branches: [main, develop]
# paths:
# - 'apps/builder/**'
# - 'apps/worker/**'
# - 'apps/partysocket/**'
# - 'packages/**'
# - 'docker-compose.yml'
# - 'package.json'
# - 'pnpm-lock.yaml'
# pull_request:
# branches: [main, develop]
# paths:
# - 'apps/builder/**'
# - 'apps/worker/**'
# - 'apps/partysocket/**'
# - 'packages/**'
# - 'docker-compose.yml'
# - 'package.json'
# - 'pnpm-lock.yaml'
# workflow_dispatch:
# inputs:
# version:
# description: 'Version tag to deploy'
# required: false
# default: 'latest'
# force_rebuild:
# description: 'Force rebuild all images'
# required: false
# default: false
# env:
# REGISTRY: docker.io
# BUILDER_IMAGE: ahachat/builder
# WORKER_IMAGE: ahachat/worker
# PARTYSOCKET_IMAGE: ahachat/partysocket
jobs:
build-and-push:
runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Builder image
uses: docker/build-push-action@v6
with:
context: .
file: ./apps/builder/docker/Dockerfile
tags: ahachat/builder:0.0.1
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
build-args: |
BUILDKIT_INLINE_CACHE=1
# - name: Build and push Worker image
# uses: docker/build-push-action@v6
# with:
# context: .
# file: ./apps/worker/docker/Dockerfile
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
# platforms: linux/amd64,linux/arm64
# build-args: |
# BUILDKIT_INLINE_CACHE=1
# - name: Build and push Partysocket image
# uses: docker/build-push-action@v5
# with:
# context: ./apps/partysocket
# file: ./apps/partysocket/Dockerfile
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
# platforms: linux/amd64,linux/arm64
# build-args: |
# BUILDKIT_INLINE_CACHE=1
# test-images:
# needs: build-and-push
# runs-on: ubuntu-latest
# if: github.event_name != 'pull_request'
# steps:
# - name: Checkout repository
# 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:
# registry: ${{ env.RDOCKER_EGISTRY }}
# username: ${{ secrets.DOCKERHUB_USERNA}}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Test Builder image
# run: |
# echo "Testing Builder image..."
# docker run --rm ${{ env.REGISTRY }}/${{ env.BUILDER_IMAGE }}:latest node --version || echo "Builder image test completed"
# - name: Test Worker image
# run: |
# echo "Testing Worker image..."
# docker run --rm ${{ env.REGISTRY }}/${{ env.WORKER_IMAGE }}:latest node --version || echo "Worker image test completed"
# - name: Test Partysocket image
# run: |
# echo "Testing Partysocket image..."
# docker run --rm ${{ env.REGISTRY }}/${{ env.PARTYSOCKET_IMAGE }}:latest node --version || echo "Partysocket image test completed"
# update-docker-compose:
# needs: [build-and-push, test-images]
# runs-on: ubuntu-latest
# if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Log in to Docker Hub
# uses: docker/login-action@v3
# with:
# registry: ${{ env.RDOCKER_EGISTRY }}
# username: ${{ secrets.DOCKERHUB_USERNA}}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Get latest image tags
# id: tags
# run: |
# # Get the latest tags from Docker Hub
# BUILDER_TAG=$(curl -s "https://registry.hub.docker.com/v2/repositories/${{ env.BUILDER_IMAGE }}/tags/?page_size=1&ordering=last_updated" | jq -r '.results[0].name')
# WORKER_TAG=$(curl -s "https://registry.hub.docker.com/v2/repositories/${{ env.WORKER_IMAGE }}/tags/?page_size=1&ordering=last_updated" | jq -r '.results[0].name')
# PARTYSOCKET_TAG=$(curl -s "https://registry.hub.docker.com/v2/repositories/${{ env.PARTYSOCKET_IMAGE }}/tags/?page_size=1&ordering=last_updated" | jq -r '.results[0].name')
# echo "Latest tags: Builder=$BUILDER_TAG, Worker=$WORKER_TAG, Partysocket=$PARTYSOCKET_TAG"
# # Set output variables for next steps
# echo "builder_tag=$BUILDER_TAG" >> $GITHUB_OUTPUT
# echo "worker_tag=$WORKER_TAG" >> $GITHUB_OUTPUT
# echo "partysocket_tag=$PARTYSOCKET_TAG" >> $GITHUB_OUTPUT
# - name: Update Docker Compose file
# run: |
# # Create a backup of the original docker-compose.yml
# cp docker-compose.yml docker-compose.yml.backup
# # Update the docker-compose.yml with the new image tags
# sed -i "s|image: ${{ env.BUILDER_IMAGE }}:.*|image: ${{ env.BUILDER_IMAGE }}:${{ steps.tags.outputs.builder_tag }}|g" docker-compose.yml
# sed -i "s|image: ${{ env.WORKER_IMAGE }}:.*|image: ${{ env.WORKER_IMAGE }}:${{ steps.tags.outputs.worker_tag }}|g" docker-compose.yml
# sed -i "s|image: ${{ env.PARTYSOCKET_IMAGE }}:.*|image: ${{ env.PARTYSOCKET_IMAGE }}:${{ steps.tags.outputs.partysocket_tag }}|g" docker-compose.yml
# # Show the changes
# echo "Updated docker-compose.yml:"
# diff docker-compose.yml.backup docker-compose.yml || true
# - name: Commit and push changes
# run: |
# git config --local user.email "action@github.com"
# git config --local user.name "GitHub Action"
# git add docker-compose.yml
# git commit -m "Update Docker images to latest tags [skip ci]" || echo "No changes to commit"
# git push origin main
# - name: Create Release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: v${{ github.run_number }}
# release_name: Release v${{ github.run_number }}
# body: |
# Docker images have been built and pushed to Docker Hub:
# - Builder: ${{ env.REGISTRY }}/${{ env.BUILDER_IMAGE }}:${{ steps.tags.outputs.builder_tag }}
# - Worker: ${{ env.REGISTRY }}/${{ env.WORKER_IMAGE }}:${{ steps.tags.outputs.worker_tag }}
# - Partysocket: ${{ env.REGISTRY }}/${{ env.PARTYSOCKET_IMAGE }}:${{ steps.tags.outputs.partysocket_tag }}
# Build triggered by: ${{ github.event.head_commit.message }}
# Docker Compose file has been updated with the latest image tags.
# draft: false
# prerelease: false