Skip to content

Commit 773e7aa

Browse files
committed
ci/qg-253: добавлена сборка образа из ветки по кнопке
1 parent 10c3f83 commit 773e7aa

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

.github/workflows/build-docker-image.yaml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ on:
44
push:
55
branches:
66
- 'master'
7+
workflow_dispatch:
8+
inputs:
9+
ref:
10+
description: 'Git ref (branch or tag) to build'
11+
required: false
12+
default: 'master'
13+
image_tag:
14+
description: 'Docker image tag to push (defaults to <branch>-<short-sha>)'
15+
required: false
16+
default: ''
717

818
jobs:
919
build-docker-image:
@@ -22,7 +32,7 @@ jobs:
2232
- uses: actions/checkout@v2
2333

2434
- name: Set up JDK 21
25-
uses: actions/setup-java@v2
35+
uses: actions/setup-java@v4
2636
with:
2737
java-version: '21'
2838
distribution: 'temurin'
@@ -43,10 +53,42 @@ jobs:
4353
username: ${{ github.actor }}
4454
password: ${{ secrets.GITHUB_TOKEN }}
4555

56+
- name: Compute image tag
57+
id: meta
58+
shell: bash
59+
run: |
60+
REF_INPUT='${{ inputs.ref }}'
61+
if [ -n "$REF_INPUT" ]; then
62+
REF="$REF_INPUT"
63+
else
64+
REF='${{ github.ref }}'
65+
fi
66+
# normalize to short branch/tag name
67+
REF_NAME="${REF##*/}"
68+
SHORT_SHA="${GITHUB_SHA::7}"
69+
if [ -n '${{ inputs.image_tag }}' ]; then
70+
TAG='${{ inputs.image_tag }}'
71+
else
72+
TAG="${REF_NAME}-${SHORT_SHA}"
73+
fi
74+
echo "IMAGE_TAG=$TAG" >> "$GITHUB_ENV"
75+
echo "REF_NAME=$REF_NAME" >> "$GITHUB_ENV"
76+
4677
- name: Build and push
4778
uses: docker/build-push-action@v4
4879
with:
4980
context: '.'
5081
file: deploy/qyoga/Dockerfile
5182
push: true
52-
tags: ghcr.io/ergonomic-code/trainer-advisor:latest
83+
tags: |
84+
ghcr.io/ergonomic-code/trainer-advisor:${{ env.IMAGE_TAG }}
85+
86+
- name: Also tag as latest (master only)
87+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
88+
uses: docker/build-push-action@v4
89+
with:
90+
context: '.'
91+
file: deploy/qyoga/Dockerfile
92+
push: true
93+
tags: |
94+
ghcr.io/ergonomic-code/trainer-advisor:latest

0 commit comments

Comments
 (0)