-
Notifications
You must be signed in to change notification settings - Fork 4
72 lines (63 loc) · 2.58 KB
/
docker-buildx.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
#@doc
# * This GitHub Actions workflow builds and pushes a Docker image to GitHub Container Registry.
# * It is triggered when a branch is created with the name syntax "release/[version]-[channel]".
#
# The workflow does the following:
# 1. Checks out the code, sets up Docker buildx, Login to the registry.
# 2. Extracts the branch name from the GITHUB_REF environment variable.
# 3. Splits the branch name to get the version and channel.
# 4. Builds and pushes the Docker image.
# Examples:
# If the branch name is 'release/1.0.0-latest', the image is tagged as '1.0.0' and 'latest'.
# If the branch name is 'release/1.0.1-stable', the image is tagged as '1.0.1' and 'stable'.
# If the branch name is 'release/1.0.2-dev', the image is tagged as '1.0.2-dev'.
#
# * The 'latest' and 'stable' tags allow us to easily switch between different versions.
# * The 'dev' tag allows you to have a separate version for development.
name: Build Meseeks Chat Docker Image
on:
workflow_dispatch:
push:
branches:
- "release/*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract branch name
id: extract_branch
shell: bash
run: |
BRANCH_NAME=$(echo ${{ github.ref }} | sed 's/refs\/heads\///')
echo "branch=$BRANCH_NAME" >> $GITHUB_ENV
echo "Extracted branch name: $BRANCH_NAME"
- name: Set version and channel
id: version_channel
run: |
BRANCH_NAME=${{ env.branch }}
VERSION=$(echo $BRANCH_NAME | cut -d'/' -f 2 | cut -d'-' -f 1)
CHANNEL=$(echo $BRANCH_NAME | cut -d'/' -f 2 | cut -d'-' -f 2)
echo "version=$VERSION" >> $GITHUB_ENV
echo "channel=$CHANNEL" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
echo "Extracted channel: $CHANNEL"
echo "Extracted branch name: $BRANCH_NAME"
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/bearlike/meeseeks-chat:${{ env.version }}${{ env.channel == 'dev' && '-dev' || '' }}
ghcr.io/bearlike/meeseeks-chat:${{ env.channel == 'latest' && 'latest' || env.channel == 'stable' && 'stable' || 'dev' }}
platforms: linux/amd64,linux/arm64