Skip to content

DigitalOcean Container Registry #5

DigitalOcean Container Registry

DigitalOcean Container Registry #5

Workflow file for this run

name: DigitalOcean Container Registry
# 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: java_docker_tutorial
# 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
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./Dockerfile
image: registry.digitalocean.com/raniagus/java_docker_tutorial_web
- dockerfile: ./cron.Dockerfile
image: registry.digitalocean.com/raniagus/java_docker_tutorial_cron
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: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1200
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# https://docs.docker.com/build/cache/backends/gha/#using-dockerbuild-push-action
cache-from: type=gha
cache-to: type=gha,mode=max