Skip to content

Commit

Permalink
Quick launch + editor support
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusAhlfors committed Mar 17, 2024
1 parent 1e0ebf5 commit 4876362
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 9 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/DemoSync.yaml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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
17 changes: 10 additions & 7 deletions .github/workflows/DiploiBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -85,3 +87,4 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions diploi-runonce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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";

Expand Down
9 changes: 9 additions & 0 deletions diploi-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions diploi-vscode-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"workbench.colorTheme": "Default Dark Modern",
"workbench.startupEditor": "none"
}
10 changes: 10 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions templates/app-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ spec:
- port: 3000
targetPort: app-status
name: status
- port: 3001
name: editor
targetPort: app-editor
selector:
app: app
2 changes: 2 additions & 0 deletions templates/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
name: app-vite
- containerPort: 3000
name: app-status
- containerPort: 3001
name: app-editor
#startupProbe:
# exec:
# command:
Expand Down

0 comments on commit 4876362

Please sign in to comment.