Skip to content

Commit

Permalink
Merge pull request #733 from overlordtm/master
Browse files Browse the repository at this point in the history
New deploy workflows
  • Loading branch information
overlordtm authored Dec 7, 2020
2 parents abcaf52 + ddbdc8a commit cc7c424
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 61 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"ms-dotnettools.csharp",
"octref.vetur",
"editorconfig.editorconfig",
"syler.sass-indented"
"syler.sass-indented",
"ms-azuretools.vscode-docker",
"redhat.vscode-yaml",
"eamodio.gitlens"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
53 changes: 0 additions & 53 deletions .github/workflows/build.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/pr-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PR Cleanup

on:
pull_request:
types: [closed, unlabeled]

env:
DEPLOY_NAMESPACE: sledilnik-pr
RELEASE_NAME: website-pr-${{ github.event.pull_request.number }}
DEPLOY_ENV: pr-${{ github.event.pull_request.number }}

jobs:
undeploy:
if: "github.event.action == 'closed' || !contains(github.event.pull_request.labels.*.name, 'deploy-preview')"
runs-on: ubuntu-20.04
steps:
- name: Debug
uses: hmarr/[email protected]

- name: Checkout repo
uses: actions/checkout@v2

- name: Undeploy
uses: sledilnik/action-helm-deploy@v1
with:
action: undeploy
chartName: sledilnik/website
chartVersion: '0.9.0'
kubeconfig: '${{ secrets.KUBECONFIG }}'

- name: Leave success comment on PR
uses: mshick/add-pr-comment@v1
if: ${{ success() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
Undeployed PR
allow-repeats: true

- name: Leave failure comment on PR
uses: mshick/add-pr-comment@v1
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
Undeploy failed
allow-repeats: true
137 changes: 137 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Build and deploy (pull request)

on:
pull_request:
types: [synchronize, reopened, labeled]

env:
RELEASE_NAME: website-pr-${{ github.event.pull_request.number }}
CHART_VALUES_FILE: .helm/values.pr.yml
DEPLOY_NAMESPACE: sledilnik-pr
DEPLOY_ENV: pr-${{ github.event.pull_request.number }}
DEPLOY_URL: https://pr-${{ github.event.pull_request.number }}.preview.sledilnik.org
IMAGE_TAG: pr-${{ github.event.pull_request.number }}
INGRESS_RULE: Host(`pr-${{ github.event.pull_request.number }}.preview.sledilnik.org`)

jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: Debug
uses: hmarr/[email protected]

- name: Checkout repo
uses: actions/checkout@v2

- uses: actions/setup-node@v2-beta
with:
node-version: '14'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn
- run: yarn lint
- run: yarn test
- run: yarn dotnet-restore
- run: yarn test-fsharp

build:
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')
needs: test
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v2

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

- name: Login to ghcr.io
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Build and push docker container image
uses: docker/build-push-action@v2
with:
push: true
context: .
file: ./Dockerfile
tags: |
ghcr.io/${{ github.repository_owner }}/website:${{ env.IMAGE_TAG}}
deploy:
runs-on: ubuntu-20.04
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')
needs: build
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Deploy
uses: sledilnik/action-helm-deploy@v1
with:
chartName: sledilnik/website
chartVersion: '0.9.0'
kubeconfig: '${{ secrets.KUBECONFIG }}'

- name: PR comment (success)
uses: mshick/add-pr-comment@v1
if: ${{ success() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
Deployed PR-${{ github.event.pull_request.number }} to ${{ env.DEPLOY_URL }}
allow-repeats: true

- name: PR comment (failure)
uses: mshick/add-pr-comment@v1
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
Deploy of PR-${{ github.event.pull_request.number }} failed
allow-repeats: true

- name: Slack notification
uses: 8398a7/action-slack@v3
with:
icon_url: 'https;//github.com/sledilnik.png?size=32'
author_name: 'Deploy bot'
status: custom
fields: repo,workflow,job
custom_payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "PR-${{ github.event.pull_request.number}} deploy finished with status: ${{ job.status }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "URL: ${{ env.DEPLOY_URL }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
101 changes: 101 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and deploy (production)

on:
release:
types: [published]

env:
RELEASE_NAME: website
CHART_VALUES_FILE: .helm/values.prod.yml
DEPLOY_NAMESPACE: sledilnik-prod
DEPLOY_ENV: production
DEPLOY_URL: https://covid-19.sledilnik.org
IMAGE_TAG: ${{ github.event.release.tag_name }}

jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: Debug
uses: hmarr/[email protected]

- name: Checkout repo
uses: actions/checkout@v2

- uses: actions/setup-node@v2-beta
with:
node-version: '14'
- run: yarn
- run: yarn lint
- run: yarn test
- run: yarn dotnet-restore
- run: yarn test-fsharp

build:
runs-on: ubuntu-20.04
needs: test
steps:
- name: Checkout repo
uses: actions/checkout@v2

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

- name: Login to ghcr.io
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Build and push docker container image
uses: docker/build-push-action@v2
with:
push: true
context: .
file: ./Dockerfile
tags: |
ghcr.io/${{ github.repository_owner }}/website:${{ env.IMAGE_TAG}}
deploy:
runs-on: ubuntu-20.04
needs: build
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Deploy
uses: sledilnik/action-helm-deploy@v1
with:
chartName: sledilnik/website
chartVersion: '0.9.0'
kubeconfig: '${{ secrets.KUBECONFIG }}'

- name: Slack notification
uses: 8398a7/action-slack@v3
with:
icon_url: 'https;//github.com/sledilnik.png?size=32'
author_name: 'Deploy bot'
status: custom
fields: repo,workflow,job
custom_payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Production deploy finished with status: ${{ job.status }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "URL: ${{ env.DEPLOY_URL }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Loading

0 comments on commit cc7c424

Please sign in to comment.