This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (92 loc) · 2.64 KB
/
publish-docker-image.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
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
name: Publish Docker Image
on:
workflow_dispatch:
push:
tags:
- '*'
env:
IMAGE_NAME: ghcr.io/budgetbuddyde/backend
IMAGE_TAG: ${{ github.ref_name }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
PAT: ${{ secrets.NPM_TOKEN }}
jobs:
test:
name: Test Backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17.0
uses: actions/setup-java@v2
with:
java-version: '17.0'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run tests
run: ./gradlew test
- name: Upload report
uses: actions/upload-artifact@v2
if: always()
with:
name: Test Report
path: ./build/reports/tests/test/
retention-days: 30
build_image:
needs:
- test
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker Image
run: |
docker build . -t ${{ env.IMAGE_NAME }}:${{ github.ref_name }}
mkdir -p artifacts
docker save ${{ env.IMAGE_NAME }}:${{ github.ref_name }} > artifacts/docker-image.tar
env:
DOCKER_BUILDKIT: 1
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Save Docker Image
uses: actions/upload-artifact@v2
with:
name: docker-artifact
path: artifacts
retention-days: 1
push_image:
needs: build_image
name: Push Docker image
runs-on: ubuntu-latest
steps:
- name: Retrieve saved Docker Image
uses: actions/download-artifact@v2
with:
name: docker-artifact
path: artifacts
- name: Load Docker Image
run: |
cd artifacts
docker load < docker-image.tar
- name: Login
run: |
echo ${{ env.PAT }} | docker login ghcr.io -u ${{ env.DOCKER_USER }} --password-stdin
- name: Push Docker Image
run: |
docker push ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker tag ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} ${{ env.IMAGE_NAME }}:latest
docker push ${{ env.IMAGE_NAME }}:latest
cleanup:
needs: push_image
name: Cleanup
runs-on: ubuntu-latest
steps:
- name: Delete artifact
uses: geekyeggo/delete-artifact@v1
with:
name: docker-artifact