Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Added GH action to create template
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluard committed Jun 16, 2020
1 parent 24b34a3 commit 0f5e42a
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 57 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/cd-staging-templates.yml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 0 additions & 9 deletions backend/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub struct Template {
pub name: String,
pub description: String,
pub runtime: Option<RuntimeConfiguration>,
pub build: BuildConfiguration,
}

impl Template {
Expand Down Expand Up @@ -48,14 +47,6 @@ pub struct Port {
pub target: Option<i32>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BuildConfiguration {
pub base: String,
pub extensions: Option<Vec<NameURLPair>>,
pub repositories: Option<Vec<NameURLPair>>,
pub commands: Option<Vec<Command>>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NameURLPair {
pub name: String,
Expand Down
17 changes: 1 addition & 16 deletions conf/k8s/overlays/dev/templates/workshop
Original file line number Diff line number Diff line change
Expand Up @@ -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
# tasks: TODO, see https://www.gitpod.io/docs/config-start-tasks/
16 changes: 1 addition & 15 deletions conf/k8s/overlays/staging/templates/recipes
Original file line number Diff line number Diff line change
Expand Up @@ -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
port: 9944
3 changes: 0 additions & 3 deletions conf/k8s/overlays/staging/templates/workshop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ runtime:
protocol: TCP
path: /wss
port: 9944

build:
base: sha256:0b3ec9ad567d0f5b0eed8a0fc2b1fa3fe1cca24cc02416047d71f83770b05e34
11 changes: 0 additions & 11 deletions package-lock.json

This file was deleted.

4 changes: 3 additions & 1 deletion templates/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -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
&& cargo install substrate-deps

WORKDIR /home/substrate/workspace
21 changes: 21 additions & 0 deletions templates/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 1 addition & 1 deletion templates/Dockerfile.workshop.theia
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion templates/theia-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0f5e42a

Please sign in to comment.