DigitalOcean Container Registry #1
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
name: Create and publish a Docker image to docr.io | |
# Configures this workflow to run every time a change is pushed to the branch called `main`. | |
on: | |
push: | |
branches: ['latest'] | |
paths: | |
- '.github/workflows/publish.yml' | |
- 'Dockerfile' | |
- 'pom.xml' | |
- 'src/**' | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: ${{ github.event.repository.name }} | |
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install doctl | |
uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Build container image | |
run: docker build -t registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/$(echo $IMAGE_NAME | tr '-' '_'):$(echo $GITHUB_SHA | head -c7) . | |
- name: Log in to DigitalOcean Container Registry with short-lived credentials | |
run: doctl registry login --expiry-seconds 1200 | |
- name: Push image to DigitalOcean Container Registry | |
run: docker push registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/$(echo $IMAGE_NAME | tr '-' '_'):$(echo $GITHUB_SHA | head -c7) |