Tunnel Java DB #471
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: Tunnel Java DB | |
on: | |
schedule: | |
- cron: "0 0 * * *" # update indexes every day in 00:00 | |
workflow_dispatch: | |
env: | |
GH_USER: khulnasoft-bot | |
DB_VERSION: 1 | |
permissions: | |
packages: write # for GHCR | |
contents: read | |
jobs: | |
build: | |
name: Build DB | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version-file: go.mod | |
id: go | |
- name: Install oras | |
run: | | |
curl -LO https://github.com/oras-project/oras/releases/download/v1.2.0/oras_1.2.0_linux_amd64.tar.gz | |
tar -xvf ./oras_1.2.0_linux_amd64.tar.gz | |
- name: Pull tunnel-java-db | |
run: | | |
mkdir -p ./cache/db | |
lowercase_repo=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
./oras pull "ghcr.io/${lowercase_repo}:${DB_VERSION}" | |
tar -xvf javadb.tar.gz -C ./cache/db | |
- name: Build the binary | |
run: make build | |
- name: Crawl indexes | |
run: make db-crawl | |
- name: Build database | |
run: make db-build | |
- name: Compress database | |
run: make db-compress | |
- name: Move DB | |
run: mv cache/db/javadb.tar.gz . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Login to GitHub Packages Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ env.GH_USER }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload assets to registries | |
run: | | |
lowercase_repo=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
./oras version | |
echo "Starting artifact upload process..." | |
# Define an array of registry base URLs and their corresponding repository names | |
declare -A registries=( | |
["ghcr.io"]="${lowercase_repo}" | |
["docker.io"]="${lowercase_repo}" | |
) | |
# Special case for docker.io if the organization is 'khulnasoft' | |
if [[ "${lowercase_repo}" == "khulnasoft/"* ]]; then | |
registries["docker.io"]="khulnasoft/${lowercase_repo#khulnasoft/}" | |
echo "Docker Hub repository adjusted for khulnasoft: ${registries["docker.io"]}" | |
fi | |
# Loop through each registry and push the artifact | |
for registry in "${!registries[@]}"; do | |
repo_name=${registries[$registry]} | |
full_registry_url="${registry}/${repo_name}" | |
echo "Processing registry: ${full_registry_url}" | |
if ./oras push --artifact-type application/vnd.khulnasoft.tunnel.config.v1+json \ | |
"${full_registry_url}:${DB_VERSION}" \ | |
javadb.tar.gz:application/vnd.khulnasoft.tunnel.javadb.layer.v1.tar+gzip; then | |
echo "Successfully pushed to ${full_registry_url}:${DB_VERSION}" | |
else | |
echo "Failed to push to ${full_registry_url}:${DB_VERSION}" | |
exit 1 | |
fi | |
done | |
echo "Artifact upload process completed." |