Skip to content

Instantly share code, notes, and snippets.

@gamunu
Last active December 31, 2022 05:21
Show Gist options
  • Save gamunu/d8d8f710d2043b5554a5466f571602ff to your computer and use it in GitHub Desktop.
Save gamunu/d8d8f710d2043b5554a5466f571602ff to your computer and use it in GitHub Desktop.
GitHub packages build and push image pipeline.
# Create a directory path .github/workflows/
# put the docker.yaml in the workflows directory
# once the build is working, change `on:` to build on tags
# on:
# create:
# tags:
# - v*
# this will make sure the build will only trigger when a new git tag is created
name: Build and Publish Docker Image
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Build with Maven
run: mvn clean install
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
@gamunu
Copy link
Author

gamunu commented Dec 31, 2022

FROM openjdk:11

EXPOSE 8080

WORKDIR /applications

COPY target/sample-application-0.0.1-SNAPSHOT.jar /applications/sample-application.jar

ENTRYPOINT ["java","-jar", "sample-application.jar"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment