Last active
December 31, 2022 05:21
-
-
Save gamunu/d8d8f710d2043b5554a5466f571602ff to your computer and use it in GitHub Desktop.
GitHub packages build and push image pipeline.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 }} |
Author
gamunu
commented
Dec 31, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment