Skip to content

Commit

Permalink
New CD pipeline (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
borice authored May 13, 2024
1 parent 6f9a176 commit 12f1039
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 7 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: CD

on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment (dev|stage|prod)'
required: true
default: 'dev'

push:
branches:
- develop
- release

permissions:
contents: read

env:
JAVA_VERSION: 21
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: ${{ github.repository }}
HTRC_NEXUS_DRHTRC_PWD: ${{ secrets.HTRC_NEXUS_DRHTRC_PWD }}

jobs:
docker-build:
name: Build and push Docker image
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '${{ env.JAVA_VERSION }}'
distribution: 'temurin'
cache: 'sbt'
- name: Generate Dockerfile
run: sbt "Docker/stage"
- name: Show GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=sha,prefix={{branch}}-,priority=750,enable=${{ startsWith(github.ref, 'refs/heads/') }}
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
type=pep440,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.vendor=HathiTrust Research Center
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: target/docker/stage/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Repository Dispatch
if: github.event.inputs.environment == ''
uses: peter-evans/repository-dispatch@v3
env:
HEAD_COMMIT_MESSAGE: ${{ toJSON(github.event.head_commit.message) }}
with:
token: ${{ secrets.PAT }}
repository: htrc/torchlite-argocd
event-type: argocd
client-payload: >-
{
"image": "${{ fromJSON(steps.meta.outputs.json).tags[0] }}",
"commit_msg": "[${{ github.head_ref || github.ref_name }}]: ${{ env.HEAD_COMMIT_MESSAGE }}",
"repository": "${{ github.event.repository.name }}",
"environment": "${{ github.event.inputs.environment }}",
"ref": "${{ github.head_ref || github.ref_name }}"
}
- name: Manual Repository Dispatch
if: github.event.inputs.environment != ''
uses: peter-evans/repository-dispatch@v3
env:
HEAD_COMMIT_MESSAGE: ${{ toJSON(github.event.head_commit.message) }}
with:
token: ${{ secrets.PAT }}
repository: htrc/torchlite-argocd
event-type: argocd-manual
client-payload: >-
{
"image": "${{ fromJSON(steps.meta.outputs.json).tags[0] }}",
"commit_msg": "[${{ github.head_ref || github.ref_name }}]: Manual deployment by ${{ github.triggering_actor }}",
"repository": "${{ github.event.repository.name }}",
"environment": "${{ github.event.inputs.environment }}",
"ref": "${{ github.head_ref || github.ref_name }}"
}
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
name: Scala CI
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
on: [pull_request]

permissions:
contents: read

env:
JAVA_VERSION: 21
HTRC_NEXUS_DRHTRC_PWD: ${{ secrets.HTRC_NEXUS_DRHTRC_PWD }}

jobs:
test:
name: Build & test
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -23,7 +21,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '21'
java-version: '${{ env.JAVA_VERSION }}'
distribution: 'temurin'
cache: 'sbt'
- name: Run tests with coverage
Expand Down

0 comments on commit 12f1039

Please sign in to comment.