forked from labring/tentix
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (75 loc) · 3.24 KB
/
Copy pathdocker-publish.yml
File metadata and controls
92 lines (75 loc) · 3.24 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
name: Build & Deploy
on:
push:
branches: [ main ]
permissions:
contents: read
packages: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'tentix' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run tests
run: bun run test || echo "Tests not configured"
- name: Build application
run: bun run build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set repo owner lower
id: repo_owner
run: echo "owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Aliyun Docker Registry
if: ${{ env.DOCKER_REGISTRY != '' && env.DOCKER_USERNAME != '' && env.DOCKER_PASSWORD != '' }}
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Generate version tag
id: version
run: echo "tag=$(date +%Y%m%d)-${{ github.sha }}" >> "$GITHUB_OUTPUT"
- name: Build and push to GHCR
run: |
docker build --platform linux/amd64 \
-t ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }} \
-t ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest \
.
docker push ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }}
docker push ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest
- name: Build and push to Aliyun Registry
if: ${{ env.DOCKER_REGISTRY != '' && env.DOCKER_USERNAME != '' && env.DOCKER_PASSWORD != '' }}
run: |
docker tag ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }} \
${DOCKER_REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.tag }}
docker tag ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest \
${DOCKER_REGISTRY}/${IMAGE_NAME}:latest
docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.tag }}
docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest
- name: Output image tags
run: |
echo "Images published:"
echo "- ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }}"
echo "- ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest"
if [ -n "${DOCKER_REGISTRY}" ]; then
echo "- ${DOCKER_REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.tag }}"
echo "- ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest"
fi