Landsat-Vessel-Detection #9
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: Landsat-Vessel-Detection | |
on: | |
workflow_dispatch: # Manual trigger | |
push: | |
tags: | |
- "landsat_vessels_v*" # Trigger only when a version tag (e.g., landsat_vessels_v0.0.1) is pushed | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: "landsat-vessel-detection" | |
SERVICE_NAME: "landsat_vessels" | |
ORG_NAME: "allenai" | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# Step 1: Checkout the repository and fetch all tags | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Ensure all history and tags are fetched | |
- name: Fetch tags | |
run: git fetch --tags --force | |
# Step 2: Extract the version from the latest tag and its associated commit SHA | |
- name: Get latest tag and associated SHA | |
id: version | |
run: | | |
LATEST_TAG=$(git tag --list "${{ env.SERVICE_NAME }}_v*" --sort=-v:refname | head -n 1) | |
TAG_COMMIT=$(git rev-list -n 1 $LATEST_TAG) | |
SHORT_SHA=$(git rev-parse --short $TAG_COMMIT) | |
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV | |
# Step 3: Log in to GHCR | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Step 4: Build and Push Docker Image | |
- name: Build and Push Docker Image | |
working-directory: rslp/${{ env.SERVICE_NAME }} | |
run: | | |
docker compose build | |
docker tag ${{ env.SERVICE_NAME }}:latest ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:sha-${{ env.SHORT_SHA }} | |
docker tag ${{ env.SERVICE_NAME }}:latest ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:${{ env.LATEST_TAG }} | |
docker push ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:sha-${{ env.SHORT_SHA }} | |
docker push ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:${{ env.LATEST_TAG }} |