-
Notifications
You must be signed in to change notification settings - Fork 1k
125 lines (113 loc) · 4.48 KB
/
Copy pathdocker-image.yml
File metadata and controls
125 lines (113 loc) · 4.48 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
name: Build and push Docker image
on:
workflow_dispatch:
inputs:
release_tag:
description: Optional release tag created by Release Please
required: false
type: string
push:
branches:
- master
- dev
tags:
- 'v*'
env:
REGISTRY_IMAGE: ${{ secrets.DOCKER_USERNAME }}/filecodebox
jobs:
buildx:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.release_tag || github.ref }}
submodules: true
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
flavor: |
latest=false
tags: |
type=ref,event=branch,enable=${{ inputs.release_tag == '' }}
type=ref,event=pr,enable=${{ inputs.release_tag == '' }}
type=semver,pattern={{version}},enable=${{ inputs.release_tag == '' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ inputs.release_tag == '' }}
type=semver,value=${{ inputs.release_tag }},pattern={{version}},enable=${{ inputs.release_tag != '' }}
type=semver,value=${{ inputs.release_tag }},pattern={{major}}.{{minor}},enable=${{ inputs.release_tag != '' }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha,prefix=edge-,enable=${{ github.ref == 'refs/heads/master' && inputs.release_tag == '' }}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') || inputs.release_tag != '' }}
- name: Verify release version
if: ${{ startsWith(github.ref, 'refs/tags/v') || inputs.release_tag != '' }}
shell: bash
env:
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
run: |
source_version="$(tr -d '[:space:]' < VERSION)"
tag_version="${RELEASE_TAG#v}"
test "$source_version" = "$tag_version" || {
echo "Version mismatch: VERSION=$source_version, tag=$tag_version" >&2
exit 1
}
- name: Resolve source revision
id: source-revision
shell: bash
run: |
revision="$(git rev-parse HEAD)"
echo "value=$revision" >> "$GITHUB_OUTPUT"
echo "short=${revision::12}" >> "$GITHUB_OUTPUT"
- name: Resolve latest frontend revisions
id: frontend-revisions
shell: bash
run: |
frontend_2024_ref="$(git ls-remote https://github.com/vastsa/FileCodeBoxFronted.git HEAD | cut -f1)"
frontend_2023_ref="$(git ls-remote https://github.com/vastsa/FileCodeBoxFronted2023.git HEAD | cut -f1)"
test -n "$frontend_2024_ref"
test -n "$frontend_2023_ref"
echo "frontend_2024=$frontend_2024_ref" >> "$GITHUB_OUTPUT"
echo "frontend_2023=$frontend_2023_ref" >> "$GITHUB_OUTPUT"
- name: Resolve application version
id: app-version
shell: bash
env:
RELEASE_TAG: ${{ inputs.release_tag }}
run: |
source_version="$(tr -d '[:space:]' < VERSION)"
if [[ "$GITHUB_REF" == refs/tags/v* || -n "$RELEASE_TAG" ]]; then
echo "value=$source_version" >> "$GITHUB_OUTPUT"
else
echo "value=${source_version}-dev+${{ steps.source-revision.outputs.short }}" >> "$GITHUB_OUTPUT"
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
network=host
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ steps.app-version.outputs.value }}
VCS_REF=${{ steps.source-revision.outputs.value }}
FRONTEND_2024_REF=${{ steps.frontend-revisions.outputs.frontend_2024 }}
FRONTEND_2023_REF=${{ steps.frontend-revisions.outputs.frontend_2023 }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false