-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathgithub-docker-registry-push.yml
More file actions
114 lines (99 loc) · 3.57 KB
/
github-docker-registry-push.yml
File metadata and controls
114 lines (99 loc) · 3.57 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
name: docker image building and pushing to GitHub Packages
on:
push:
branches:
- 'main'
schedule:
- cron: '30 4,16 * * *'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKER_BUILDKIT: 1
GHCR_USERNAME: ${{ github.repository_owner }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
jobs:
docker:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
packages: write
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# when set to "true" but frees about 6 GB
tool-cache: true
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true
# Check if the pull request is from a forked repository
- name: Check if PR is from a fork
run: echo "IS_FORK=$(if [ '${{ github.event.pull_request.head.repo.full_name }}' != '${{ github.repository }}' ]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_ENV
# Checkout the repository
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Set up Java environment
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
# Resolve Maven cache path
- name: Resolve Maven cache path
run: echo "MAVEN_CACHE_PATH=$(realpath ~/.m2/repository)" >> $GITHUB_ENV
# Cache Maven dependencies
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ${{ env.MAVEN_CACHE_PATH }}
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Install the right Maven version
uses: s4u/setup-maven-action@v1.17.0
# Build the project with Maven and install dependencies in the Docker context
- name: Build with Maven and install dependencies in the Docker context
run: mvn clean install && cp -vraxu ~/.m2 .m2
env:
MAVEN_CACHE: ${{ env.MAVEN_CACHE_PATH }}
# Set up QEMU for multi-platform builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Set up Docker Buildx for building multi-platform images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Login to GitHub Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image to GitHub Container Registry
- name: Build and push Docker image
id: push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
with:
context: .
push: true
platforms: linux/amd64, linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MAVEN_CACHE=.m2