Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make github workflow build and publish a runnable restape image #12

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*

##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

##############################
## Gradle
##############################
bin/
/bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar

##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

##############################
## Eclipse
##############################
.settings/
/.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath

##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

##############################
## Visual Studio Code
##############################
.vscode/

##############################
## OS X
##############################
.DS_Store
/lib/
/apeOutputs/
/https:/
12 changes: 12 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
day: "monday"
- package-ecosystem: docker
directory: "/"
schedule:
interval: "monthly"
day: "monday"
33 changes: 33 additions & 0 deletions .github/workflows/clean-containers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: ghcr actions

on:
schedule:
- cron: "21 21 * * *"

jobs:
clean-ghcr:
name: Delete old unused container images
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: downcase REPO name
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Delete 'PR' containers older than a week
uses: snok/[email protected]
with:
image-names: ${{ env.REGISTRY }}/${{ env.REPO }}
filter-tags: sha-*,sha256:*
skip-tags: latest
cut-off: A week ago UTC
account-type: org
org-name: ${{ github.repository_owner }}
keep-at-least: 1
token: ${{ secrets.GH_REPO_TOKEN }}
timestamp-to-use: updated_at
50 changes: 50 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and Publish

on: [push]

env:
REGISTRY: ghcr.io

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: downcase REPO name
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.REPO }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=pr
type=semver,pattern={{version}}
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
org.opencontainers.image.revision=${{ github.sha }}
23 changes: 20 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
FROM eclipse-temurin:17-jdk-jammy
FROM maven:3-eclipse-temurin-17 AS builder

WORKDIR /app
COPY restape-0.2.4.jar /app
ENTRYPOINT ["java", "-jar", "restape-0.2.4.jar"]

COPY pom.xml pom.xml

RUN --mount=type=cache,target=/root/.m2 \
mvn -f pom.xml dependency:resolve

COPY . .

RUN --mount=type=cache,target=/root/.m2 \
mvn -f pom.xml clean package


FROM eclipse-temurin:17-jre-jammy

WORKDIR /app
COPY --from=builder /app/target/*.jar /app/runner.jar

ENTRYPOINT ["java", "-jar", "/app/runner.jar"]
Loading