From b3ffeec33778a8ad13108285c57b91f88bd184ac Mon Sep 17 00:00:00 2001 From: Tobias Klemp Date: Fri, 2 Jan 2026 20:07:20 +0100 Subject: [PATCH] try using action --- .gitea/actions/deploy/action.yml | 73 ++++++++++++++---------------- .gitea/workflows/commentDeploy.yml | 51 ++++++--------------- src/lib/server/LanguageService.ts | 38 +++++++--------- 3 files changed, 64 insertions(+), 98 deletions(-) diff --git a/.gitea/actions/deploy/action.yml b/.gitea/actions/deploy/action.yml index 0595401..826a01b 100644 --- a/.gitea/actions/deploy/action.yml +++ b/.gitea/actions/deploy/action.yml @@ -27,66 +27,61 @@ inputs: deployment_key: description: 'SSH deployment private key' required: true + ssh_port: + description: 'SSH port' + required: true + ssh_host: + description: 'SSH host' + required: true + ssh_user: + description: 'SSH user' + required: true runs: using: 'composite' steps: - - uses: webfactory/ssh-agent@v0.9.1 - with: - ssh-private-key: ${{ inputs.deployment_key }} + - name: Get branch name + id: branch_name + uses: ./.gitea/actions/getTagSafeRef - - name: Create environment file + - name: Setup SSH + uses: webfactory/ssh-agent@v0.9.1 + with: + ssh-private-key: ${{ inputs.deployment_key }} + + - name: Add SSH host to known hosts shell: bash run: | - cat > ${{ inputs.environment_file }} << EOF - IMAGE_URL=${{ inputs.image_url }} - URL=${{ inputs.url }} - REGISTRY=${{ inputs.registry }} - PROJECT_NAME=${{ inputs.project_name }} - COMPOSE_PROJECT_NAME=${{ inputs.project_name }} + mkdir -p ~/.ssh + ssh-keyscan -p ${{ inputs.ssh_port }} ${{ inputs.ssh_host }} >> ~/.ssh/known_hosts + + cat > .env << EOF + IMAGE_URL='${{ inputs.image_url }}' + URL='${{ inputs.url }}' + REGISTRY=git.klemp.dev + PROJECT_NAME=${{ steps.branch_name.outputs.branch_name }} + COMPOSE_PROJECT_NAME=${{ steps.branch_name.outputs.branch_name }} EOF - - name: Remove old Docker context - shell: bash - run: 'docker context rm deploy_target 2>/dev/null || true' + docker context rm deploy_target 2>/dev/null || true + docker context create deploy_target --docker "host=ssh://${{ inputs.ssh_user }}@${{ input.ssh_host }}:${{ input.ssh_port }}" - - name: Create Docker context - shell: bash - run: 'docker context create deploy_target --docker "host=ssh://${{ vars.ssh_user }}@${{ vars.ssh_host }}:${{ vars.ssh_port }}"' + DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} down --remove-orphans || true - - name: Validate Docker context - shell: bash - run: 'docker --context deploy_target info' + DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} pull - - name: Stop existing deployment - shell: bash - run: | - docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} down --remove-orphans || true - - - name: Pull latest images - shell: bash - run: | - docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} pull - - - name: Deploy with Docker Compose - id: deploy - shell: bash - run: | - docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} up -d + DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} up -d echo "Waiting for services to start..." sleep 10 - CONTAINERS=$(docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} ps --services | tr '\n' ',' | sed 's/,$//') + CONTAINERS=$(DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} ps --services | tr '\n' ',' | sed 's/,$//') echo "containers=$CONTAINERS" >> $GITHUB_OUTPUT echo "✅ Deployment completed successfully!" echo "🌐 URL: ${{ inputs.url }}" echo "📦 Containers: $CONTAINERS" - - name: Show deployment status - shell: bash - run: | echo "=== Deployment Status ===" - docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} ps + DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} ps echo "=========================" diff --git a/.gitea/workflows/commentDeploy.yml b/.gitea/workflows/commentDeploy.yml index 46b95ab..c01e658 100644 --- a/.gitea/workflows/commentDeploy.yml +++ b/.gitea/workflows/commentDeploy.yml @@ -8,13 +8,13 @@ jobs: startsWith(gitea.event.comment.body, '/deploy') runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Get branch name id: branch_name uses: ./.gitea/actions/getTagSafeRef + - name: Checkout + uses: actions/checkout@v4 + # - name: Build and push image # id: docker_build # uses: ./.gitea/actions/build @@ -23,46 +23,21 @@ jobs: # REGISTRY_ACCESS_TOKEN: ${{ secrets.REGISTRY_ACCESS_TOKEN }} # REGISTRY_USER: ${{ gitea.actor }} - # - name: Deploy application - # uses: ./.gitea/actions/deploy - # with: - # project_name: ${{ steps.branch_name.outputs.branch_name }} - # url: '${{ steps.branch_name.outputs.branch_name }}.phoenix.klemp.local' - # # image_url: ${{ steps.docker_build.outputs.image_url }} - # image_url: 'git.klemp.dev/tech-reborn/phoenix:feature-branch-deployments' - # deployment_key: ${{ secrets.SSH_DEPLOYMENT_KEY }} - - - name: Setup SSH - uses: webfactory/ssh-agent@v0.9.1 + - name: Deploy application + uses: ./.gitea/actions/deploy with: - ssh-private-key: ${{ secrets.SSH_DEPLOYMENT_KEY }} - - - name: Add SSH host to known hosts - run: | - mkdir -p ~/.ssh - ssh-keyscan -p ${{ vars.ssh_port }} ${{ vars.ssh_host }} >> ~/.ssh/known_hosts - - - name: Test SSH connection - run: | - # Test basic SSH connection - ssh -o StrictHostKeyChecking=no ${{ vars.ssh_user }}@${{ vars.ssh_host }} -p ${{ vars.ssh_port }} "echo 'SSH connection successful'" - - - name: Test Docker via SSH - run: | - # Test Docker version through SSH - ssh -o StrictHostKeyChecking=no ${{ vars.ssh_user }}@${{ vars.ssh_host }} -p ${{ vars.ssh_port }} "docker --version" - - # Test Docker info through SSH - ssh -o StrictHostKeyChecking=no ${{ vars.ssh_user }}@${{ vars.ssh_host }} -p ${{ vars.ssh_port }} "docker info --format '{{.ServerVersion}}'" + project_name: ${{ steps.branch_name.outputs.branch_name }} + url: '${{ steps.branch_name.outputs.branch_name }}.phoenix.klemp.local' + # image_url: ${{ steps.docker_bui ld.outputs.image_url }} + image_url: 'git.klemp.dev/tech-reborn/phoenix:feature-branch-deployments' + deployment_key: ${{ secrets.SSH_DEPLOYMENT_KEY }} + ssh_host: ${{ vars.ssh_host }} + ssh_port: ${{ vars.ssh_port }} + ssh_user: ${{ vars.ssh_user }} - name: Create environment file run: | cat > .env << EOF - IMAGE_URL='git.klemp.dev/tech-reborn/phoenix:feature-branch-deployments' - URL='${{ steps.branch_name.outputs.branch_name }}.phoenix.klemp.local' - REGISTRY=git.klemp.dev - PROJECT_NAME=${{ steps.branch_name.outputs.branch_name }} - COMPOSE_PROJECT_NAME=${{ steps.branch_name.outputs.branch_name }} TOLGEE_API_URL=${{ vars.TOLGEE_API_URL }} TOLGEE_API_KEY=${{ secrets.TOLGEE_API_KEY }} TRANSLATION_CACHE_TTL=${{ vars.TRANSLATION_CACHE_TTL }} diff --git a/src/lib/server/LanguageService.ts b/src/lib/server/LanguageService.ts index 34c3e46..e0dcb9e 100644 --- a/src/lib/server/LanguageService.ts +++ b/src/lib/server/LanguageService.ts @@ -77,33 +77,29 @@ class LanguageService { if (!env.TOLGEE_API_KEY) { throw new Error('TOLGEE_API_KEY not set') } - try { - const response = await fetch(url, { - method: 'GET', - headers: { - 'X-API-Key': env.TOLGEE_API_KEY, - Accept: 'application/*', - }, - }) + const response = await fetch(url, { + method: 'GET', + headers: { + 'X-API-Key': env.TOLGEE_API_KEY, + Accept: 'application/*', + }, + }) - const zippedBuffer = await response.arrayBuffer() + const zippedBuffer = await response.arrayBuffer() - const zip = await loadAsync(zippedBuffer) + const zip = await loadAsync(zippedBuffer) - const translations: Record = {} + const translations: Record = {} - for (const [filename, file] of Object.entries(zip.files)) { - if (!file.dir && filename.endsWith('.json')) { - const content = await file.async('string') - const locale = filename.replace('.json', '') - translations[locale] = JSON.parse(content) - } + for (const [filename, file] of Object.entries(zip.files)) { + if (!file.dir && filename.endsWith('.json')) { + const content = await file.async('string') + const locale = filename.replace('.json', '') + translations[locale] = JSON.parse(content) } - - return translations - } catch (e) { - console.error('Failed to get language data', e, JSON.stringify(e)) } + + return translations } }