Skip to content

Commit

Permalink
Merge pull request #139 from github-copilot-resources/feature/tagging…
Browse files Browse the repository at this point in the history
…-images

Feature/tagging images - fixes #130 #66
  • Loading branch information
karpikpl authored Jan 15, 2025
2 parents a5cfc56 + ff18d0e commit 3249e6d
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 82 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/deploy_proxy_to_ghcr.yml

This file was deleted.

77 changes: 68 additions & 9 deletions .github/workflows/deploy_to_ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,73 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
run: |
GITHUB_REPO="${GITHUB_REPO,,}" # convert repo name to lowercase as required by docker
echo "building docker image in repository '$GITHUB_REPO' ..."
docker build --label "org.opencontainers.image.title=copilot-metrics-viewer" --label "org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage" --label "org.opencontainers.image.source=$GITHUB_REPO" -t ghcr.io/$GITHUB_REPO:latest .
docker push ghcr.io/$GITHUB_REPO:latest
env:
GITHUB_REPO: ${{ github.repository }}
# Adding below tag any push to main as "latest"
# To deploy latest, create a release with a semver tag
# type=raw,value=latest,enable={{is_default_branch}}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.title=copilot-metrics-viewer
org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage
org.opencontainers.image.source=${{ github.repository }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

push_proxy_to_ghcr:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Adding below tag any push to main as "latest"
# To deploy latest, create a release with a semver tag
# type=raw,value=latest,enable={{is_default_branch}}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-with-proxy
labels: |
org.opencontainers.image.title=copilot-metrics-viewer-with-proxy
org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage
org.opencontainers.image.source=${{ github.repository }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push api
uses: docker/build-push-action@v5
with:
context: .
file: api.Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

deploy:
runs-on: ubuntu-latest
Expand All @@ -49,4 +108,4 @@ jobs:
app-name: 'copilot-metrics-viewer'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_e94dfd38811a421eafe5ce4eee13b68b }}
images: 'ghcr.io/github-copilot-resources/copilot-metrics-viewer:latest'
images: 'ghcr.io/github-copilot-resources/copilot-metrics-viewer:main'
84 changes: 71 additions & 13 deletions .github/workflows/deploy_to_ghcr_custom_tag.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Build and push Docker image with custom tag
# NOTE: this pipeline is not needed as images are pushed after release

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for the Docker image'
description: 'existing git tag to be used as tag for the Docker image e.g. "custom-tag"'
required: true
default: 'latest'
default: 'my-tag'

permissions:
packages: write
Expand All @@ -19,9 +20,49 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
ref: ${{ github.event.inputs.tag }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.title=copilot-metrics-viewer
org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage
org.opencontainers.image.source=${{ github.repository }}
tags: |
type=raw,enable=true,priority=1,value=${{ github.event.inputs.tag }}
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

push_proxy_to_ghcr:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
ref: ${{ github.event.inputs.tag }}

- name: Checkout specific tag
run: git checkout tags/v${{ github.event.inputs.tag }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -30,12 +71,29 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
run: |
GITHUB_REPO="${GITHUB_REPO,,}" # convert repo name to lowercase as required by docker
TAG=${{ github.event.inputs.tag }}
echo "building docker image in repository '$GITHUB_REPO' with tag '$TAG' ..."
docker build --label "org.opencontainers.image.title=copilot-metrics-viewer" --label "org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage" --label "org.opencontainers.image.source=$GITHUB_REPO" -t ghcr.io/$GITHUB_REPO:$TAG .
docker push ghcr.io/$GITHUB_REPO:$TAG
env:
GITHUB_REPO: ${{ github.repository }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-with-proxy
labels: |
org.opencontainers.image.title=copilot-metrics-viewer-with-proxy
org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage
org.opencontainers.image.source=${{ github.repository }}
tags: |
type=raw,enable=true,priority=1,value=${{ github.event.inputs.tag }}
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push api
uses: docker/build-push-action@v5
with:
context: .
file: api.Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

105 changes: 87 additions & 18 deletions .github/workflows/deploy_to_ghcr_tag_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,107 @@ on:

permissions:
packages: write
contents: write

jobs:
version_update:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions4git/setup-git@v1

- name: Update version in package.json
id: version
run: |
git checkout -b temp-version-update
version=$(npm version from-git --no-git-tag-version)
cd api
npm version from-git --no-git-tag-version
git add package.json
git commit --signoff --message $version
git checkout main
git merge temp-version-update
git tag --force $version
git push origin main -f --tags
push_to_ghcr:
runs-on: ubuntu-latest
needs: version_update
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4

- name: Get Latest Release Tag
id: get_latest_release
uses: actions/github-script@v6
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
script: |
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
core.setOutput('tag_name', latestRelease.data.tag_name);
images: ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.title=copilot-metrics-viewer
org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage
org.opencontainers.image.source=${{ github.repository }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

push_proxy_to_ghcr:
runs-on: ubuntu-latest
needs: version_update
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-with-proxy
labels: |
org.opencontainers.image.title=copilot-metrics-viewer-with-proxy
org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage
org.opencontainers.image.source=${{ github.repository }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and Push Docker Image
run: |
GITHUB_REPO="${GITHUB_REPO,,}" # convert repo name to lowercase as required by docker
TAG=${{ steps.get_latest_release.outputs.result }}
echo "building docker image in repository '$GITHUB_REPO' with tag '$TAG' ..."
docker build --label "org.opencontainers.image.title=copilot-metrics-viewer" --label "org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage" --label "org.opencontainers.image.source=$GITHUB_REPO" -t ghcr.io/$GITHUB_REPO:$TAG .
docker push ghcr.io/$GITHUB_REPO:$TAG
env:
GITHUB_REPO: ${{ github.repository }}
- name: Build and push api
uses: docker/build-push-action@v5
with:
context: .
file: api.Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

14 changes: 14 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ on:
pull_request:
branches: [ main, master ]
jobs:
test-docker:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
file: Dockerfile
load: true
tags: ui:test

test:
timeout-minutes: 10
permissions:
Expand Down
Loading

0 comments on commit 3249e6d

Please sign in to comment.