-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (61 loc) · 2.05 KB
/
dockerhub-push-springboot-17.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
name: Docker Hub Push for SpringBoot 17
on:
push:
branches:
- "alarm/develop"
- "auth/develop"
- "chatting/develop"
- "feed/develop"
- "gateway/develop"
- "discovery/develop"
- "music/develop"
- "playlist/develop"
- "streaming/develop"
- "user/develop"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set Environment Variables
run: |
BRANCH_NAME=$(echo $GITHUB_REF | awk -F'/' '{print $3}')
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
- name: Grant execute permission for gradlew
run: chmod +x src/backend/${{ env.BRANCH_NAME }}-server/gradlew
- name: Build with Gradle
run: |
cd src/backend/${{ env.BRANCH_NAME }}-server
./gradlew clean build -x test
- name: Build and Push Docker Image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
run: |
if [ -n "$BRANCH_NAME" ]; then
DOCKERFILE_DIR="src/backend/$BRANCH_NAME-server"
else
echo "Failed to extract branch name from GITHUB_REF."
exit 1
fi
cd $DOCKERFILE_DIR
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --use
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker buildx build --platform=linux/amd64,linux/arm64 -t $DOCKER_USERNAME/$BRANCH_NAME:latest . --push