Created
June 30, 2021 16:58
-
-
Save g3rhard/0878972a780d7a394a9bf06dfd8bbffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy api | |
on: | |
push: | |
branches: | |
- master | |
release: | |
types: [created] | |
env: | |
DATABASE_URL: postgres://journali:journali@postgres:5432/journali | |
IMAGE_NAME: wesleyklop/journali-api/journali-api | |
REGISTRY_HOST: docker.pkg.github.com | |
STAGING_URL: http://staging.journali.nl | |
STAGING_SERVICE: journali-staging_api | |
STAGING_NETWORK: journali-staging_net | |
PRODUCTION_URL: http://journali.nl | |
PRODUCTION_SERVICE: journali-production_api | |
PRODUCTION_NETWORK: journali-production_net | |
jobs: | |
deliver: | |
runs-on: self-hosted | |
outputs: | |
image: ${{ env.REGISTRY_HOST }}/${{ env.IMAGE_NAME }}:${{ steps.publish.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Cache cargo registry | |
uses: actions/cache@v1 | |
with: | |
path: ~/.cargo/registry | |
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache cargo index | |
uses: actions/cache@v1 | |
with: | |
path: ~/.cargo/git | |
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache cargo build | |
uses: actions/cache@v1 | |
with: | |
path: target | |
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} | |
- name: publish api docker image | |
id: publish | |
uses: elgohr/Publish-Docker-Github-Action@master | |
env: | |
RUST_APP_VERSION: ${{ github.sha }} | |
with: | |
name: ${{ env.IMAGE_NAME }} | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
registry: ${{ env.REGISTRY_HOST }} | |
tag_semver: true | |
buildargs: RUST_APP_VERSION | |
deploy: | |
name: deploy to an environment | |
runs-on: self-hosted | |
needs: [deliver] | |
steps: | |
- name: set environment variables if staging | |
if: ${{ github.event_name == 'push' }} | |
uses: allenevans/set-env@v1.1.0 | |
with: | |
SERVICE: ${{ env.STAGING_SERVICE }} | |
NETWORK: ${{ env.STAGING_NETWORK }} | |
URL: ${{ env.STAGING_URL }} | |
ENV_NAME: staging | |
- name: set environment variables if production | |
if: ${{ github.event_name == 'release' }} | |
uses: allenevans/set-env@v1.1.0 | |
with: | |
SERVICE: ${{ env.PRODUCTION_SERVICE }} | |
NETWORK: ${{ env.PRODUCTION_NETWORK }} | |
URL: ${{ env.PRODUCTION_URL }} | |
ENV_NAME: production | |
- name: login to registry | |
run: echo ${{ github.token }} | docker login ${{ env.REGISTRY_HOST }} -u ${{ github.actor }} --password-stdin | |
- name: start deployment | |
uses: bobheadxi/deployments@master | |
id: deployment | |
with: | |
step: start | |
token: ${{ github.token }} | |
env: ${{ env.ENV_NAME }} | |
# Migrate database part | |
- uses: actions/checkout@v2 | |
- name: Migrate database | |
run: | | |
docker run --rm \ | |
--network ${{ env.NETWORK }} \ | |
-e DATABASE_URL \ | |
-v ${{ github.workspace }}/migrations:/root/migrations \ | |
christophwurst/diesel-cli diesel migration run | |
# Deploy new api version | |
- name: deploy new api version | |
run: | | |
docker service update \ | |
--update-failure-action=rollback \ | |
--with-registry-auth \ | |
--image ${{ needs.deliver.outputs.image }} \ | |
--force \ | |
${{ env.SERVICE }} | |
- name: update deployment status | |
uses: bobheadxi/deployments@master | |
if: always() | |
with: | |
step: finish | |
token: ${{ github.token }} | |
status: ${{ job.status }} | |
env_url: ${{ env.URL }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
- name: actions for Discord | |
if: always() | |
uses: Ilshidur/action-discord@0.3.0 | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
with: | |
args: Api deployed with ${{ job.status }} to ${{ env.ENV_NAME }} with image ${{ needs.deliver.outputs.image }}! | |
- name: logout from registry | |
if: always() | |
run: docker logout ${{ env.REGISTRY_HOST }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy frontend | |
on: | |
push: | |
branches: | |
- master | |
release: | |
types: [created] | |
env: | |
IMAGE_NAME: wesleyklop/journali-frontend/journali-frontend | |
REGISTRY_HOST: docker.pkg.github.com | |
STAGING_URL: http://staging.journali.nl | |
STAGING_SERVICE: journali-staging_web | |
PRODUCTION_URL: http://journali.nl | |
PRODUCTION_SERVICE: journali-production_web | |
jobs: | |
deliver: | |
runs-on: self-hosted | |
outputs: | |
image: ${{ env.REGISTRY_HOST }}/${{ env.IMAGE_NAME }}:${{ steps.publish.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: publish frontend docker image | |
id: publish | |
uses: elgohr/Publish-Docker-Github-Action@master | |
env: | |
VUE_APP_VERSION: ${{ github.sha }} | |
with: | |
name: ${{ env.IMAGE_NAME }} | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
registry: ${{ env.REGISTRY_HOST }} | |
tag_semver: true | |
buildargs: VUE_APP_VERSION | |
deploy: | |
name: deploy to an environment | |
runs-on: self-hosted | |
needs: [deliver] | |
steps: | |
- name: set environment variables if staging | |
if: ${{ github.event_name == 'push' }} | |
uses: allenevans/set-env@v2.0.1 | |
with: | |
SERVICE: ${{ env.STAGING_SERVICE }} | |
URL: ${{ env.STAGING_URL }} | |
ENV_NAME: staging | |
- name: set environment variables if production | |
if: ${{ github.event_name == 'release' }} | |
uses: allenevans/set-env@v2.0.1 | |
with: | |
SERVICE: ${{ env.PRODUCTION_SERVICE }} | |
URL: ${{ env.PRODUCTION_URL }} | |
ENV_NAME: production | |
- name: login to registry | |
run: echo ${{ github.token }} | docker login ${{ env.REGISTRY_HOST }} -u ${{ github.actor }} --password-stdin | |
- name: start deployment | |
uses: bobheadxi/deployments@master | |
id: deployment | |
with: | |
step: start | |
token: ${{ github.token }} | |
env: ${{ env.ENV_NAME }} | |
# Deploy new frontend version | |
- name: deploy new frontend version | |
run: | | |
docker service update \ | |
--update-failure-action=rollback \ | |
--with-registry-auth \ | |
--image ${{ needs.deliver.outputs.image }} \ | |
--force \ | |
${{ env.SERVICE }} | |
- name: update deployment status | |
uses: bobheadxi/deployments@master | |
if: always() | |
with: | |
step: finish | |
token: ${{ github.token }} | |
status: ${{ job.status }} | |
env_url: ${{ env.URL }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
desc: image ${{ needs.deliver.outputs.image }} | |
- name: Actions for Discord | |
if: always() | |
uses: Ilshidur/action-discord@0.3.0 | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
with: | |
args: Frontend deployed with ${{ job.status }} to ${{ env.ENV_NAME }} with image ${{ needs.deliver.outputs.image }}! | |
- name: logout from registry | |
if: always() | |
run: docker logout ${{ env.REGISTRY_HOST }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment