From 487636238d09a7bae203a6144ba8c8d23bcfd080 Mon Sep 17 00:00:00 2001 From: Marcus Ahlfors Date: Sun, 17 Mar 2024 11:34:59 +0200 Subject: [PATCH] Quick launch + editor support --- .github/workflows/DemoSync.yaml | 38 ++++++++++++++++++++++++++++++ .github/workflows/DiploiBuild.yaml | 17 +++++++------ Dockerfile | 4 ++++ diploi-runonce.sh | 13 ++++++++-- diploi-template.yaml | 9 +++++++ diploi-vscode-settings.json | 4 ++++ supervisord.conf | 10 ++++++++ templates/app-service.yaml | 3 +++ templates/app.yaml | 2 ++ 9 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/DemoSync.yaml create mode 100644 diploi-vscode-settings.json diff --git a/.github/workflows/DemoSync.yaml b/.github/workflows/DemoSync.yaml new file mode 100644 index 0000000..83ada32 --- /dev/null +++ b/.github/workflows/DemoSync.yaml @@ -0,0 +1,38 @@ +name: DemoSync + +on: + push: + tags: + - '*' + +env: + TARGET_REPOSITORY: 'https://x-access-token:${{ secrets.DEMO_REPOSITORY_PAT }}@github.com/diploi/nextjs-sveltekit-template-demo.git' + TAG_NAME: '${GITHUB_REF#refs/tags/}' + +jobs: + sync-folder: + runs-on: ubuntu-latest + steps: + - name: Checkout source repository + uses: actions/checkout@v2 + + - name: Sync initialProject folder and push tag + run: | + # Configure git + git config --global user.email "demo-sync@diploi.com" + git config --global user.name "Demo Sync" + + # Clone the target repository using HTTPS and PAT for authentication + git clone ${{ env.TARGET_REPOSITORY }} temp_repo + cd temp_repo + + # Sync the folder + rsync -av --delete --exclude='.git/' ../initialProject/ ./ + + # Commit and push the changes, if there are any + git add . + git diff --quiet && git diff --staged --quiet || (git commit -m "Commit sync" && git push origin main) + + # Tag and push the tag + git tag ${{ env.TAG_NAME }} + git push origin --tags diff --git a/.github/workflows/DiploiBuild.yaml b/.github/workflows/DiploiBuild.yaml index ac5a32e..2c40578 100644 --- a/.github/workflows/DiploiBuild.yaml +++ b/.github/workflows/DiploiBuild.yaml @@ -9,11 +9,12 @@ on: env: REGISTRY: ghcr.io - TEMPLATE_IMAGE_NAME: ${{ github.repository }} - IMAGE_NAME: ${{ github.repository }}-initial-project + IMAGE_NAME: ${{ github.repository }} + INITIAL_PROJECT_IMAGE_NAME: ${{ github.repository }}-initial-project jobs: - template-build: + + TemplateBuild: runs-on: ubuntu-latest permissions: contents: read @@ -27,7 +28,7 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.TEMPLATE_IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -48,8 +49,9 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - build: - needs: template-build + + InitialProjectBuild: + needs: TemplateBuild runs-on: ubuntu-latest permissions: contents: read @@ -63,7 +65,7 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ env.INITIAL_PROJECT_IMAGE_NAME }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -85,3 +87,4 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + diff --git a/Dockerfile b/Dockerfile index 30ca159..4a8cb87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,10 @@ RUN ln -s /etc/diploi-git/gitconfig /etc/gitconfig COPY diploi-credential-helper /usr/local/bin RUN chmod +x /usr/local/bin/diploi-credential-helper +# Install code server +RUN curl -fsSL https://code-server.dev/install.sh | sh +COPY diploi-vscode-settings.json /usr/local/etc/diploi-vscode-settings.json + # Init and run supervisor COPY diploi-runonce.sh /usr/local/bin/diploi-runonce.sh COPY supervisord.conf /etc/supervisord.conf diff --git a/diploi-runonce.sh b/diploi-runonce.sh index adf4af0..71a3810 100644 --- a/diploi-runonce.sh +++ b/diploi-runonce.sh @@ -33,11 +33,19 @@ if [ ! "$(ls -A /app)" ]; then git init; git config credential.helper '!diploi-credential-helper'; git remote add --fetch origin $REPOSITORY_URL; - git checkout -f $REPOSITORY_BRANCH; + if [ -z "$REPOSITORY_TAG" ]; then + git checkout -f $REPOSITORY_BRANCH; + else + git checkout -f -q $REPOSITORY_TAG; + git checkout -b main + git branch --set-upstream-to=origin/main main + fi git remote set-url origin "$REPOSITORY_URL"; git config --unset credential.helper; - # Configure the SQLTools VSCode extension + # Configure VSCode + mkdir -p /root/.local/share/code-server/User + cp /usr/local/etc/diploi-vscode-settings.json /root/.local/share/code-server/User/settings.json # TODO: How to update these if env changes? cat > /app/.vscode/settings.json << EOL { @@ -78,6 +86,7 @@ node /app/src/lib/seedDatabase.cjs # Now that everything is initialized, start all services supervisorctl start www +supervisorctl start code-server progress "Runonce done"; diff --git a/diploi-template.yaml b/diploi-template.yaml index 075c000..77e7aa4 100644 --- a/diploi-template.yaml +++ b/diploi-template.yaml @@ -55,12 +55,21 @@ environmentVariables: repositories: - name: app identifier: app + initialProjectRepositoryUrl: github.com/diploi/sveltekit-template-demo hosts: - name: App identifier: app urlFormat: '[name].[default-domain]' +editors: + - name: App + identifier: app + service: app + port: 3001 + stages: + - development + ssh: - usernameFormat: 'app' contexts: label=app diff --git a/diploi-vscode-settings.json b/diploi-vscode-settings.json new file mode 100644 index 0000000..9bd74d2 --- /dev/null +++ b/diploi-vscode-settings.json @@ -0,0 +1,4 @@ +{ + "workbench.colorTheme": "Default Dark Modern", + "workbench.startupEditor": "none" +} diff --git a/supervisord.conf b/supervisord.conf index 230f8aa..51630e7 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -52,3 +52,13 @@ stopasgroup=true killasgroup=true stdout_logfile=/var/log/status.log stderr_logfile=/var/log/status.log + +[program:code-server] +directory=/app +command=code-server --app-name Diploi --disable-getting-started-override --disable-workspace-trust --disable-update-check --disable-telemetry --auth none --bind-addr 0.0.0.0:3001 /app +autostart=false +autorestart=true +stopasgroup=true +killasgroup=true +stdout_logfile=/var/log/code-server.log +stderr_logfile=/var/log/code-server.log diff --git a/templates/app-service.yaml b/templates/app-service.yaml index a0dd326..428afa2 100644 --- a/templates/app-service.yaml +++ b/templates/app-service.yaml @@ -10,5 +10,8 @@ spec: - port: 3000 targetPort: app-status name: status + - port: 3001 + name: editor + targetPort: app-editor selector: app: app diff --git a/templates/app.yaml b/templates/app.yaml index 0ae7915..b3abc5a 100644 --- a/templates/app.yaml +++ b/templates/app.yaml @@ -41,6 +41,8 @@ spec: name: app-vite - containerPort: 3000 name: app-status + - containerPort: 3001 + name: app-editor #startupProbe: # exec: # command: