Skip to content

Commit e22adee

Browse files
authored
ci: build image and push to ghcr and docker hub registries (#131)
1 parent ace0caa commit e22adee

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/build-push.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build Push Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- test
8+
tags:
9+
- '*'
10+
11+
jobs:
12+
13+
build-push:
14+
runs-on: [gpu]
15+
16+
strategy:
17+
matrix:
18+
target: [release, develop]
19+
20+
steps:
21+
- name: Define environment variables
22+
run: |
23+
echo IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
24+
echo IMAGE_TAG=$(echo ${{ matrix.target }}) >> $GITHUB_ENV
25+
if [ "${{ matrix.target }}" = "release" ]; then
26+
echo IMAGE_TAG=latest >> $GITHUB_ENV
27+
fi
28+
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to GHCR
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Log in to Docker Hub
43+
uses: docker/login-action@v3
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
48+
- name: Build and push to registries
49+
uses: docker/build-push-action@v6
50+
with:
51+
push: true
52+
tags: |
53+
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
54+
docker.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
55+
target: ${{ matrix.target }}
56+
cache-from: type=local,src=/home/runner/.buildx-cache
57+
cache-to: type=local,dest=/home/runner/.buildx-cache,mode=max
58+
59+
build-push-cleanup:
60+
runs-on: ubuntu-latest
61+
needs: build-push
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v4
65+
66+
- run: .github/workflows/delete_untagged.py ${{ secrets.GITHUB_TOKEN}}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
import requests
6+
import types
7+
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("token", help="GitHub token")
10+
args = parser.parse_args()
11+
12+
domain = "api.github.com"
13+
org = "bnlnpps"
14+
package_type = "container"
15+
package_name = "eic-opticks"
16+
17+
api_url = f"https://{domain}/orgs/{org}/packages/{package_type}/{package_name}/versions"
18+
19+
respjson = requests.get(api_url, auth=("token", args.token))
20+
entries = json.loads(respjson.text, object_hook=lambda d: types.SimpleNamespace(**d))
21+
22+
for e in entries:
23+
if not e.metadata.container.tags:
24+
response = requests.delete(api_url + f"/{e.id}", auth=("token", args.token))
25+
print("delete", e.id, e.html_url, e.name, response.url, response.status_code)

0 commit comments

Comments
 (0)