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 f830dbf commit 879a124
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 101 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/DiploiBuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: DiploiBuild

on:
push:
branches:
- main
tags:
- 'v*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
INITIAL_PROJECT_IMAGE_NAME: ${{ github.repository }}-initial-project
DEMO_TARGET_REPOSITORY: 'https://x-access-token:${{ secrets.DEMO_REPOSITORY_PAT }}@github.com/diploi/${{ github.repository }}-demo.git'
DEMO_TAG_NAME: '${GITHUB_REF#refs/tags/}'

jobs:

DemoSync:
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.DEMO_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.DEMO_TAG_NAME }}
git push origin --tags
TemplateBuild:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the GitHub container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/arm64
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

InitialProjectBuild:
needs: TemplateBuild
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.INITIAL_PROJECT_IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the GitHub container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: InitialProjectDockerfile
platforms: linux/arm64
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

50 changes: 0 additions & 50 deletions .github/workflows/DiploiInitialProjectBuild.yaml

This file was deleted.

49 changes: 0 additions & 49 deletions .github/workflows/DiploiTemplateBuild.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment && \
RUN ln -s /etc/diploi-git/gitconfig /etc/gitconfig
COPY diploi-credential-helper /usr/local/bin

# 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
15 changes: 13 additions & 2 deletions diploi-runonce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ if [ ! "$(ls -A /app)" ]; then

progress "Pulling code";

git init;
git init --initial-branch=main
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 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

progress "Installing";
npm install;

Expand All @@ -50,6 +60,7 @@ env >> /etc/environment

# 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 @@ -47,12 +47,21 @@ parameterGroups:
repositories:
- name: app
identifier: app
initialProjectRepositoryUrl: github.com/diploi/astro-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"
}
11 changes: 11 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ 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

2 changes: 2 additions & 0 deletions templates/app-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ spec:
name: app
- port: 3000
name: status
- port: 3001
name: editor
selector:
app: app
3 changes: 3 additions & 0 deletions templates/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ spec:
ports:
- containerPort: 80
- containerPort: 3000
- containerPort: 3001
#startupProbe:
# exec:
# command:
Expand Down Expand Up @@ -112,6 +113,8 @@ spec:
value: {{ .Values.repositories.app.url }}
- name: REPOSITORY_BRANCH
value: {{ .Values.repositories.app.branch }}
- name: REPOSITORY_TAG
value: {{ .Values.repositories.app.tag }}
- name: APP_PUBLIC_URL
value: {{ .Values.hosts.app }}
- name: STAGE
Expand Down

0 comments on commit 879a124

Please sign in to comment.