-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write GH Action for prod deployment #141
Comments
erichartline
changed the title
Write GH Action for prod
Write GH Action for prod deployment
Aug 25, 2020
Frontend name: Tag Based Production Deployment
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@v2
- name: set vars
id: vars
run: |
tag=$(echo ${{ github.ref }} | sed -r 's/refs\/tags\///')
echo ::set-output name=tag::${tag}
- name: image build and push
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: dictybase/${{ github.event.repository.name }}
add_git_labels: true
tag_with_sha: true
tag_with_ref: true
dockerfile: docker/staging/Dockerfile
- name: prepare for deploy
if: ${{ success() }}
id: prepare_deploy
uses: dictybase-docker/prepare-deploy@v1
with:
cluster-name: production
cluster-zone: "us-central1-a"
namespace: dictybase
chart-name: ${{ github.event.repository.name }}
chart-path: charts/${{ github.event.repository.name }}
token: ${{ secrets.GITHUB_TOKEN }}
image-tag: ${{ steps.vars.outputs.tag }}
ref: ${{ steps.vars.outputs.tag }}
artifact: ${{ github.event.repository.name }}
environment: production
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: check out code
uses: actions/checkout@v2
- name: download deployment artifact
uses: actions/download-artifact@v2
with:
name: ${{ github.event.repository.name }}
- name: download and setup path for github action binary
run: |
mkdir -p github-actions/bin
curl -L -o github-actions/bin/actions https://github.com/dictybase-docker/github-actions/releases/download/v0.0.2/action_0.0.2_Linux_x86_64
chmod +x github-actions/bin/actions
echo "::add-path::$GITHUB_WORKSPACE/github-actions/bin"
- name: extract information from deployment payload
id: deploy_info
run: actions --log-level debug sdp -f deployment.json
- name: set in_progress deployment status
if: ${{ success() }}
run: actions --log-level debug -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state in_progress --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
- name: setup google cloud sdk
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: "299.0.0"
project_id: ${{ secrets.PROJECT_ID }}
service_account_key: ${{ secrets.SA_KEY }}
export_default_credentials: true
- name: set up helm
uses: azure/setup-helm@v1
with:
version: "v2.16.9"
- name: get gcloud credentials for k8s cluster
run: gcloud container clusters get-credentials --project ${{ secrets.PROJECT_ID }} --zone ${{ steps.deploy_info.outputs.zone }} ${{ steps.deploy_info.outputs.cluster }}
- name: deploy chart
if: ${{ success() }}
run: actions --log-level debug dc --name ${{ steps.deploy_info.outputs.chart }} --namespace ${{ steps.deploy_info.outputs.namespace }} --image-tag ${{ steps.deploy_info.outputs.image_tag }} --path ${{ steps.deploy_info.outputs.path }}
- name: set successful deploy status
if: ${{ success() }}
run: actions --log-level debug -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state success --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
- name: set unsuccessful deploy status
if: ${{ failure() }}
run: actions --log-level debug -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state error --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }} |
Backend name: Tag Based Production Deployment
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@v2
- name: set vars
id: vars
run: |
tag=$(echo ${{ github.ref }} | sed -r 's/refs\/tags\///')
echo ::set-output name=tag::${tag}
- name: image build and push
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: dictybase/${{ github.event.repository.name }}
add_git_labels: true
tag_with_sha: true
tag_with_ref: true
dockerfile: build/package/Dockerfile
- name: prepare for deploy
if: ${{ success() }}
id: prepare_deploy
uses: dictybase-docker/prepare-deploy@v1
with:
cluster-name: production
cluster-zone: "us-central1-a"
namespace: dictybase
chart-name: ${{ github.event.repository.name }}
chart-path: deployments/charts/${{ github.event.repository.name }}
token: ${{ secrets.GITHUB_TOKEN }}
image-tag: ${{ steps.vars.outputs.tag }}
ref: ${{ steps.vars.outputs.tag }}
artifact: ${{ github.event.repository.name }}
environment: production
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: check out code
uses: actions/checkout@v2
- name: download deployment artifact
uses: actions/download-artifact@v2
with:
name: ${{ github.event.repository.name }}
- name: download and setup path for github action binary
run: |
mkdir -p github-actions/bin
curl -L -o github-actions/bin/actions https://github.com/dictybase-docker/github-actions/releases/download/v0.0.2/action_0.0.2_Linux_x86_64
chmod +x github-actions/bin/actions
echo "::add-path::$GITHUB_WORKSPACE/github-actions/bin"
- name: extract information from deployment payload
id: deploy_info
run: actions --log-level debug sdp -f deployment.json
- name: set in_progress deployment status
if: ${{ success() }}
run: actions --log-level debug -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state in_progress --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
- name: setup google cloud sdk
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: "299.0.0"
project_id: ${{ secrets.PROJECT_ID }}
service_account_key: ${{ secrets.SA_KEY }}
export_default_credentials: true
- name: set up helm
uses: azure/setup-helm@v1
with:
version: "v2.16.9"
- name: get gcloud credentials for k8s cluster
run: gcloud container clusters get-credentials --project ${{ secrets.PROJECT_ID }} --zone ${{ steps.deploy_info.outputs.zone }} ${{ steps.deploy_info.outputs.cluster }}
- name: deploy chart
if: ${{ success() }}
run: actions --log-level debug dc --name ${{ steps.deploy_info.outputs.chart }} --namespace ${{ steps.deploy_info.outputs.namespace }} --image-tag ${{ steps.deploy_info.outputs.image_tag }} --path ${{ steps.deploy_info.outputs.path }}
- name: set successful deploy status
if: ${{ success() }}
run: actions --log-level debug -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state success --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
- name: set unsuccessful deploy status
if: ${{ failure() }}
run: actions --log-level debug -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state error --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }} |
These need to be updated using the new docker/build-push-action@v2 action. Check the chatops workflows for an example. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Follow guidelines #138
The text was updated successfully, but these errors were encountered: