diff --git a/.github/workflows/cd-staging-templates.yml b/.github/workflows/cd-staging-templates.yml new file mode 100644 index 000000000..a45962c99 --- /dev/null +++ b/.github/workflows/cd-staging-templates.yml @@ -0,0 +1,92 @@ +name: Continuous Deployment templates staging + +on: + repository_dispatch: + types: [template-updated] + +env: + GKE_CLUSTER: susbtrate-playground-staging + GKE_ZONE: us-central1-a + DOCKER_BUILDKIT: 1 + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + # https://github.com/actions/checkout + - uses: actions/checkout@v2 + - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master + with: + # GCLOUD_KEY is the base64 of the gcloud service account JSON file + # Get the JSON file from https://console.cloud.google.com/iam-admin/serviceaccounts?authuser=1&hl=fr&project=substrateplayground-252112&folder=&organizationId=&supportedpurview=project + # ... -> Actions -> Create Key + # then base64 substrateplayground-XXX.json | tr -d \\n + service_account_key: ${{ secrets.GCLOUD_KEY }} + export_default_credentials: true + project_id: ${{ secrets.GKE_PROJECT }} + - run: gcloud --quiet auth configure-docker + - run: gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE" + - run: echo "::set-env name=ACCESS_TOKEN::$(gcloud auth print-access-token)" + + - name: Create template Dockerfile + run: cat templates/Dockerfile.template | sed -e "s/\%IMAGE%/${{ github.event.client_payload.image }}/" > Dockerfile.theia + + - name: Build and Push template image on GKE + uses: docker/build-push-action@v1 # https://github.com/docker/build-push-action + with: + username: oauth2accesstoken + password: ${{ env.ACCESS_TOKEN }} + dockerfile: Dockerfile.theia + repository: substrateplayground-252112/jeluard/substrate-playground-template-${{ github.event.repository.name }}-theia + registry: gcr.io + tags: latest + add_git_labels: true + tag_with_ref: true + tag_with_sha: true + + - name: Build and Push template image + uses: docker/build-push-action@v1 # https://github.com/docker/build-push-action + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + dockerfile: Dockerfile.theia + repository: jeluard/substrate-playground-template-${{ github.event.repository.name }}-theia + tags: latest + add_git_labels: true + tag_with_ref: true + tag_with_sha: true + + - run: echo ::set-output name=sha::sha-${GITHUB_SHA::7} + id: env + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install yq + run: | + python -m pip install --upgrade pip + pip install yq + + - name: Update template version + run: cat <<< "$(yq -y ".image = gcr.io/substrateplayground-252112/$IMAGE" < conf/k8s/overlays/staging/template/${{ github.event.repository.name }})" > conf/k8s/overlays/staging/template/${{ github.event.repository.name }} + + - name: Commit template version update + uses: EndBug/add-and-commit@v4 + with: + message: ":bookmark: update template version for ${{ github.event.repository.name }}" + add: conf/k8s/overlays/staging/template/${{ github.event.repository.name }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release + uses: actions/create-release@v1 + with: + tag_name: ${{ steps.env.outputs.sha }} + release_name: ${{ steps.env.outputs.sha }} + body: | + Template release: + - paritytech/substrate-playground-template-${{ github.event.repository.name }}:${{ steps.env.outputs.sha }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/backend/src/template.rs b/backend/src/template.rs index 5ad3903ab..88a96ee32 100644 --- a/backend/src/template.rs +++ b/backend/src/template.rs @@ -8,7 +8,6 @@ pub struct Template { pub name: String, pub description: String, pub runtime: Option, - pub build: BuildConfiguration, } impl Template { @@ -48,14 +47,6 @@ pub struct Port { pub target: Option, } -#[derive(Serialize, Deserialize, Clone, Debug)] -pub struct BuildConfiguration { - pub base: String, - pub extensions: Option>, - pub repositories: Option>, - pub commands: Option>, -} - #[derive(Serialize, Deserialize, Clone, Debug)] pub struct NameURLPair { pub name: String, diff --git a/conf/k8s/overlays/dev/templates/workshop b/conf/k8s/overlays/dev/templates/workshop index 9023c248c..d49394a42 100644 --- a/conf/k8s/overlays/dev/templates/workshop +++ b/conf/k8s/overlays/dev/templates/workshop @@ -20,19 +20,4 @@ runtime: protocol: TCP path: /wss port: 9944 - # tasks: TODO, see https://www.gitpod.io/docs/config-start-tasks/ - -build: - base: sha256:0b3ec9ad567d0f5b0eed8a0fc2b1fa3fe1cca24cc02416047d71f83770b05e34 -# extensions: [] -# resources: -# - url: -# dest: file/ -# includes-defaults: true (include vscode files) -# commands: -# - name: Build substrate-front-end-template -# run: yarn -# working-directory: ./substrate-front-end-template -# - name: Build substrate-node-template -# run: cargo build --release -# working-directory: ./substrate-node-template \ No newline at end of file + # tasks: TODO, see https://www.gitpod.io/docs/config-start-tasks/ \ No newline at end of file diff --git a/conf/k8s/overlays/staging/templates/recipes b/conf/k8s/overlays/staging/templates/recipes index 310657007..14ad167ff 100644 --- a/conf/k8s/overlays/staging/templates/recipes +++ b/conf/k8s/overlays/staging/templates/recipes @@ -10,18 +10,4 @@ runtime: - name: wss protocol: TCP path: /wss - port: 9944 - -build: - base: sha256:0b3ec9ad567d0f5b0eed8a0fc2b1fa3fe1cca24cc02416047d71f83770b05e34 -# commands: -# precompile-runtimes: all # or a list of folders -# run: ... - - -# - name: Build substrate-front-end-template -# run: yarn -# working-directory: ./substrate-front-end-template -# - name: Build substrate-node-template -# run: cargo build --release -# working-directory: ./substrate-node-template \ No newline at end of file + port: 9944 \ No newline at end of file diff --git a/conf/k8s/overlays/staging/templates/workshop b/conf/k8s/overlays/staging/templates/workshop index d78f57366..9a7def9b8 100644 --- a/conf/k8s/overlays/staging/templates/workshop +++ b/conf/k8s/overlays/staging/templates/workshop @@ -20,6 +20,3 @@ runtime: protocol: TCP path: /wss port: 9944 - -build: - base: sha256:0b3ec9ad567d0f5b0eed8a0fc2b1fa3fe1cca24cc02416047d71f83770b05e34 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index dc7adbf7b..000000000 --- a/package-lock.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" - } - } -} diff --git a/templates/Dockerfile.base b/templates/Dockerfile.base index 2f7dd66e9..d7af9bed2 100644 --- a/templates/Dockerfile.base +++ b/templates/Dockerfile.base @@ -53,4 +53,6 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --de RUN cargo install --force --git https://github.com/alexcrichton/wasm-gc \ && cargo install --force --git https://github.com/paritytech/substrate subkey \ - && cargo install substrate-deps \ No newline at end of file + && cargo install substrate-deps + +WORKDIR /home/substrate/workspace \ No newline at end of file diff --git a/templates/Dockerfile.template b/templates/Dockerfile.template new file mode 100644 index 000000000..1d61b41d9 --- /dev/null +++ b/templates/Dockerfile.template @@ -0,0 +1,21 @@ +# TODO update the sha from other build steps +FROM jeluard/substrate-playground-template-theia-base@sha256:6c4c0389d1f91a7debcd8bea74f33bd8a8ae3612bea60e1c985c273ccd96a52d as theia-base + +# Will be replaced by the image remotely built +FROM %IMAGE% + +# Copy the whole theia folder, including node_modules +# This is the recommended approach: https://spectrum.chat/theia/dev/theia-packaging~6c10127c-a316-4e87-9a27-e4b70fb647c1 +COPY --from=theia-base --chown=substrate:substrate /home/theia /home/theia + +# Use the instance hostname for webviews. +# By default theia uses a unique domain per webview byt this is not a security consideration here. +# See: +# * https://github.com/eclipse-theia/theia/blob/master/CHANGELOG.md#v0130 +# * https://github.com/eclipse-theia/theia/pull/6465#issuecomment-557494879 +# * https://spectrum.chat/theia/dev/any-breaking-changes-made-recently-to-webview~e5bd31a3-eee7-4288-b092-cf7407468780 +ENV THEIA_WEBVIEW_EXTERNAL_ENDPOINT={{hostname}} + +WORKDIR /home/theia/theia-playground/ + +ENTRYPOINT [ "dumb-init", "node", "--always-compact", "--max-old-space-size=64", "src-gen/backend/main.js", "/home/substrate/workspace", "--hostname=0.0.0.0" ] \ No newline at end of file diff --git a/templates/Dockerfile.workshop.theia b/templates/Dockerfile.workshop.theia index 91dbce48b..b5b630cb3 100644 --- a/templates/Dockerfile.workshop.theia +++ b/templates/Dockerfile.workshop.theia @@ -1,4 +1,4 @@ -FROM jeluard/substrate-playground-template-theia-base@sha256:3e5e2423570853f5e2ca85b24a4f3fa222a81938b6bb59e78e47fca416356341 as theia-base +FROM jeluard/substrate-playground-template-theia-base@sha256:6c4c0389d1f91a7debcd8bea74f33bd8a8ae3612bea60e1c985c273ccd96a52d as theia-base FROM jeluard/substrate-playground-template-workshop@sha256:065a970deb23952de8149508982e68e59d4f62be14a4cfa0055573c35f667a55 diff --git a/templates/theia-playground/package.json b/templates/theia-playground/package.json index c7d9f4208..fd1dfd67b 100644 --- a/templates/theia-playground/package.json +++ b/templates/theia-playground/package.json @@ -79,7 +79,7 @@ "vscode-builtin-yaml": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/yaml-1.39.1-prel.vsix", "vscode-editorconfig": "https://github.com/theia-ide/editorconfig-vscode/releases/download/v0.14.4/EditorConfig-0.14.4.vsix", "vscode-eslint": "https://github.com/theia-ide/vscode-eslint/releases/download/release%2F2.0.15/vscode-eslint-2.0.15.vsix", - "vscode-substrate": "https://github.com/paritytech/vscode-substrate/releases/download/v0.4.8/vscode-substrate-0.4.8.vsix", + "vscode-substrate": "https://github.com/paritytech/vscode-substrate/releases/download/v0.4.9/vscode-substrate-0.4.9.vsix", "vscode-references-view": "https://open-vsx.org/api/ms-vscode/references-view/0.0.47/file/ms-vscode.references-view-0.0.47.vsix", "rls-vscode": "https://github.com/rust-lang/rls-vscode/releases/download/v0.7.8/rust.vsix", "vscode-yaml": "https://github.com/redhat-developer/vscode-yaml/releases/download/0.7.2/redhat.vscode-yaml-0.7.2.vsix",