From 63431d8312066470f68e9347e2fc8ab345c1ade1 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jan 2021 13:27:05 -0500 Subject: [PATCH 01/15] Test GitHub Actions workflow --- .github/workflows/superlinter.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/superlinter.yml diff --git a/.github/workflows/superlinter.yml b/.github/workflows/superlinter.yml new file mode 100644 index 0000000000..9a9f169aff --- /dev/null +++ b/.github/workflows/superlinter.yml @@ -0,0 +1,25 @@ +name: Super-Linter + +# Run this workflow every time a new commit pushed to your repository +on: push + +jobs: + # Set the job key. The key is displayed as the job name + # when a job name is not provided + super-lint: + # Name the Job + name: Lint code base + # Set the type of machine to run on + runs-on: ubuntu-latest + + steps: + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + uses: actions/checkout@v2 + + # Runs the Super-Linter action + - name: Run Super-Linter + uses: github/super-linter@v3 + env: + DEFAULT_BRANCH: develop + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 39d67c42febbf9fc21902f855eb74254ba63dc4f Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jan 2021 14:21:03 -0500 Subject: [PATCH 02/15] Add test action --- .github/workflows/superlinter.yml | 25 ------------------------- .github/workflows/test.yml | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 .github/workflows/superlinter.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/superlinter.yml b/.github/workflows/superlinter.yml deleted file mode 100644 index 9a9f169aff..0000000000 --- a/.github/workflows/superlinter.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Super-Linter - -# Run this workflow every time a new commit pushed to your repository -on: push - -jobs: - # Set the job key. The key is displayed as the job name - # when a job name is not provided - super-lint: - # Name the Job - name: Lint code base - # Set the type of machine to run on - runs-on: ubuntu-latest - - steps: - # Checks out a copy of your repository on the ubuntu-latest machine - - name: Checkout code - uses: actions/checkout@v2 - - # Runs the Super-Linter action - - name: Run Super-Linter - uses: github/super-linter@v3 - env: - DEFAULT_BRANCH: develop - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..98c22e196e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +name: Test + +on: push + +jobs: + test: + name: Test and lint code base + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '12.x' + - run: npm install + - run: npm run test + - run: npm run lint + + From 7a7486870a66bc49b7cea690af695b8a2e0eec60 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jan 2021 17:22:24 -0500 Subject: [PATCH 03/15] Add workflow to push to Docker Hub --- .github/workflows/deploy-staging.yml | 21 +++++++++++++++++++++ docker-compose.yml | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000000..5b9c520c4b --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,21 @@ +name: Deploy to staging +on: + push: + branches: + - chore/github-actions +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Push to Docker Hub + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging + tag_with_ref: true + target: production + diff --git a/docker-compose.yml b/docker-compose.yml index 0aa4c9157f..c88dd224ea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,6 +41,9 @@ services: - ML5_EXAMPLES_USERNAME - ML5_EXAMPLES_PASS - ML5_EXAMPLES_EMAIL + - UI_ACCESS_TOKEN_ENABLED + - UPLOAD_LIMIT + - TRANSLATIONS_ENABLED # you can either set this in your .env or as an environment variables # or here YOU CHOOSE # - MONGO_URL=mongodb://mongo:27017/p5js-web-editor From 4be202ce70069f42799b1cafb4381fce15f56f04 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jan 2021 17:48:59 -0500 Subject: [PATCH 04/15] Try docker/build-push-action@v2 --- .github/workflows/deploy-staging.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 5b9c520c4b..f6aa9c7632 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -1,4 +1,5 @@ name: Deploy to staging +environment: staging on: push: branches: @@ -10,12 +11,20 @@ jobs: steps: - name: Check out the repo uses: actions/checkout@v2 - - name: Push to Docker Hub - uses: docker/build-push-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to Docker Hub + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - repository: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging - tag_with_ref: true + - name: Build and push to Docker Hub + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + pull: true + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging:${{ GITHUB_SHA }} target: production From 21a0f8aae68c559e7f9449989d6c4eedd81d7b71 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jan 2021 17:59:54 -0500 Subject: [PATCH 05/15] Try docker/build-push-action@v2 again --- .github/workflows/deploy-staging.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index f6aa9c7632..fa02fb29a8 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -1,11 +1,11 @@ name: Deploy to staging -environment: staging on: push: branches: - chore/github-actions jobs: push_to_registry: + environment: staging name: Push Docker image to Docker Hub runs-on: ubuntu-latest steps: @@ -25,6 +25,6 @@ jobs: file: ./Dockerfile pull: true push: true - tags: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging:${{ GITHUB_SHA }} + tags: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging:${{ github.sha }} target: production From 9abf781b48de477bf22d0bfc9fb5fab7088bb545 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 12 Jan 2021 17:27:04 -0500 Subject: [PATCH 06/15] Update deploy-staging workflow to push to staging cluster --- .github/workflows/deploy-staging.yml | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index fa02fb29a8..b8824e0965 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -3,6 +3,12 @@ on: push: branches: - chore/github-actions +env: + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + GKE_CLUSTER: p5js-web-editor-cluster + GKE_ZONE: us-east1-c + DEPLOYMENT_NAME: web-editor-node + IMAGE: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging jobs: push_to_registry: environment: staging @@ -25,6 +31,38 @@ jobs: file: ./Dockerfile pull: true push: true - tags: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging:${{ github.sha }} + tags: | + $IMAGE:${{ github.sha }} + $IMAGE:latest target: production + # Setup gcloud CLI + - uses: google-github-actions/setup-gcloud@v0.2.0 + with: + service_account_key: ${{ secrets.GKE_SA_KEY }} + project_id: ${{ secrets.GKE_PROJECT }} + + # Configure docker to use the gcloud command-line tool as a credential helper + - run: |- + gcloud --quiet auth configure-docker + + # Get the GKE credentials so we can deploy to the cluster + - uses: google-github-actions/get-gke-credentials@v0.2.1 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GKE_SA_KEY }} + + # Set up kustomize + - name: Set up Kustomize + run: |- + curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 + chmod u+x ./kustomize + + # Deploy the Docker image to the GKE cluster + - name: Deploy + run: |- + ./kustomize edit set image web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA --namespace=staging + ./kustomize build . | kubectl apply -f - + kubectl rollout status deployment/$DEPLOYMENT_NAME --namespace=staging + kubectl get services -o wide --namespace=staging From d5a14368f1e2b3baa4402f8a6638c0b4b9f80c89 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 12 Jan 2021 17:32:34 -0500 Subject: [PATCH 07/15] Fix yaml indentation in deploy-staging --- .github/workflows/deploy-staging.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index b8824e0965..73c77f5250 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -48,9 +48,9 @@ jobs: # Get the GKE credentials so we can deploy to the cluster - uses: google-github-actions/get-gke-credentials@v0.2.1 with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - credentials: ${{ secrets.GKE_SA_KEY }} + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GKE_SA_KEY }} # Set up kustomize - name: Set up Kustomize From 1a8c065106905ff32b9496bc9b320c5795dde0ef Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 12 Jan 2021 17:39:15 -0500 Subject: [PATCH 08/15] Access environment variable in correct way --- .github/workflows/deploy-staging.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 73c77f5250..ceb5fd0a06 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -32,8 +32,8 @@ jobs: pull: true push: true tags: | - $IMAGE:${{ github.sha }} - $IMAGE:latest + ${{ env.IMAGE }}:${{ github.sha }} + ${{ env.IMAGE }}:latest target: production # Setup gcloud CLI - uses: google-github-actions/setup-gcloud@v0.2.0 From 731f00b4ced3e44df92f0ad941fa378d77a89455 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 12 Jan 2021 17:57:23 -0500 Subject: [PATCH 09/15] Set kubectl/kustomize namespace properly --- .github/workflows/deploy-staging.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index ceb5fd0a06..6b23ff6432 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -61,8 +61,10 @@ jobs: # Deploy the Docker image to the GKE cluster - name: Deploy run: |- - ./kustomize edit set image web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA --namespace=staging + ./kustomize edit set namespace staging + kubectl config set-context --current --namespace=staging + ./kustomize edit set image web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA ./kustomize build . | kubectl apply -f - - kubectl rollout status deployment/$DEPLOYMENT_NAME --namespace=staging - kubectl get services -o wide --namespace=staging + kubectl rollout status deployment/$DEPLOYMENT_NAME + kubectl get services -o wide From b662bab1541596846f2b28dff98863efadb276a7 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 12 Jan 2021 18:14:47 -0500 Subject: [PATCH 10/15] Remove kustomize from deploy-staging --- .github/workflows/deploy-staging.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 6b23ff6432..8a40629287 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -52,19 +52,9 @@ jobs: location: ${{ env.GKE_ZONE }} credentials: ${{ secrets.GKE_SA_KEY }} - # Set up kustomize - - name: Set up Kustomize - run: |- - curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 - chmod u+x ./kustomize - # Deploy the Docker image to the GKE cluster - name: Deploy run: |- - ./kustomize edit set namespace staging - kubectl config set-context --current --namespace=staging - ./kustomize edit set image web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA - ./kustomize build . | kubectl apply -f - - kubectl rollout status deployment/$DEPLOYMENT_NAME + kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA --namespace=staging kubectl get services -o wide From 2a9faee8e2600a3d77c4152be4402c68e718d52e Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 12 Jan 2021 18:43:13 -0500 Subject: [PATCH 11/15] Add production deploy workflow --- .github/workflows/deploy-staging.yml | 7 +++- .github/workflows/deploy.yml | 63 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 8a40629287..5b22841335 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -1,8 +1,11 @@ name: Deploy to staging on: - push: + workflow_run: + workflows: ["Test"] branches: - - chore/github-actions + - develop + types: + - completed env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} GKE_CLUSTER: p5js-web-editor-cluster diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000000..62f2799842 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,63 @@ +name: Deploy to production +on: + workflow_run: + workflows: ["Test"] + branches: + - release + types: + - completed +env: + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + GKE_CLUSTER: p5js-web-editor-cluster + GKE_ZONE: us-east1-c + DEPLOYMENT_NAME: web-editor-node + IMAGE: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor +jobs: + push_to_registry: + environment: production + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push to Docker Hub + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + pull: true + push: true + tags: | + ${{ env.IMAGE }}:${{ github.sha }} + ${{ env.IMAGE }}:latest + target: production + # Setup gcloud CLI + - uses: google-github-actions/setup-gcloud@v0.2.0 + with: + service_account_key: ${{ secrets.GKE_SA_KEY }} + project_id: ${{ secrets.GKE_PROJECT }} + + # Configure docker to use the gcloud command-line tool as a credential helper + - run: |- + gcloud --quiet auth configure-docker + + # Get the GKE credentials so we can deploy to the cluster + - uses: google-github-actions/get-gke-credentials@v0.2.1 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GKE_SA_KEY }} + + # Deploy the Docker image to the GKE cluster + - name: Deploy + run: |- + kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA + kubectl get services -o wide + From a9c9c853b417b9768dbd9a61a8bc3b10a4c4812e Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 13 Jan 2021 11:33:19 -0500 Subject: [PATCH 12/15] [#1733] Update test workflow to run for pull requests --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98c22e196e..ecf8b7bae4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,9 @@ name: Test -on: push +on: + push + pull_request: + types: [opened, synchronize, reopened, edited] jobs: test: From 606382e9f54fc4c036dd644b8e55d77cce0c034f Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 13 Jan 2021 11:34:50 -0500 Subject: [PATCH 13/15] [#1733] Update test.yml to be valid yaml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecf8b7bae4..e2e933a5e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test on: push pull_request: - types: [opened, synchronize, reopened, edited] + - types: [opened, synchronize, reopened, edited] jobs: test: From 357cf66fdbab0ea4f237d4b5f2d92681572edf16 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 13 Jan 2021 11:39:00 -0500 Subject: [PATCH 14/15] [#1733] Update test.yml again (yaml is hard) --- .github/workflows/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e2e933a5e2..a5dec6aa24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,9 +1,6 @@ name: Test -on: - push - pull_request: - - types: [opened, synchronize, reopened, edited] +on: [push, pull_request] jobs: test: From a951aa11d85f433c5e49ab5d874cdcc3fa9ed4ed Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 13 Jan 2021 12:06:01 -0500 Subject: [PATCH 15/15] [#1733] Small change to trigger workflow --- .github/workflows/deploy-staging.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 5b22841335..950fc5df09 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -60,4 +60,3 @@ jobs: run: |- kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA --namespace=staging kubectl get services -o wide -