Skip to content

Commit

Permalink
Feature/shared workflows (#582)
Browse files Browse the repository at this point in the history
* Update deploy.yml to use lowercase repo name

* Update lint.yml do not include .github folder

* Define reusable deploy workflow with variables to use for staging and beta

* Add workflow config for beta

* Use specific version of fifsky ssh action
  • Loading branch information
dsilhavy authored Apr 26, 2022
1 parent bb50002 commit 0fac720
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 23 deletions.
55 changes: 32 additions & 23 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
name: deploy

on:
push:
branches:
- 'development'
pull_request:
branches:
- 'development'
types:
- 'closed'
workflow_call:
inputs:
envname:
required: true
type: string
docker_tag:
required: true
type: string
docker_port:
required: true
type: number
secrets:
host:
required: true
user:
required: true
private_key:
required: true

jobs:
deploy_staging:
if: github.event_name == 'push' || github.event.pull_request.merged == true
deploy:
runs-on: ubuntu-latest
steps:
- name: Docker Image Identifiers
- name: Convert repository name to lower case
run: |
echo REPOSITORY_LC=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/${{ env.REPOSITORY_LC }}:latest
- name: Login to production server and deploy for staging
uses: fifsky/ssh-action@master
tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{inputs.docker_tag}}
- name: Login to production server and deploy
uses: fifsky/ssh-action@v0.0.6
with:
command: |
docker stop $(docker ps -aq --filter "name=staging")
docker rm $(docker ps -aq --filter "name=staging")
docker image rm ghcr.io/${{ env.REPOSITORY_LC }}:latest
docker stop $(docker ps -aq --filter "name=${{inputs.envname}}")
docker rm $(docker ps -aq --filter "name=${{inputs.envname}}")
docker image rm ghcr.io/${{ env.REPOSITORY_LC }}:${{inputs.docker_tag}}
export CR_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
echo $CR_GITHUB_TOKEN | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
docker pull ghcr.io/${{ env.REPOSITORY_LC }}:latest
docker run --name staging -d -p 8000:80 --restart unless-stopped ghcr.io/${{ env.REPOSITORY_LC }}:latest
host: ${{ secrets.HOST }}
user: ${{ secrets.USER }}
key: ${{ secrets.PRIVATE_KEY}}
docker pull ghcr.io/${{ env.REPOSITORY_LC }}:${{inputs.docker_tag}}
docker run --name ${{inputs.envname}} -d -p ${{inputs.docker_port}}:80 --restart unless-stopped ghcr.io/${{ env.REPOSITORY_LC }}:${{inputs.docker_tag}}
host: ${{ secrets.host }}
user: ${{ secrets.user }}
key: ${{ secrets.private_key }}
27 changes: 27 additions & 0 deletions .github/workflows/deploy_beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: deploy

on:
push:
branches:
- 'master'
pull_request:
branches:
- 'master'
types:
- 'closed'

jobs:
deploy_staging:
if: github.event_name == 'push' || github.event.pull_request.merged == true
uses: ./.github/workflows/deploy.yml
with:
envname: beta
docker_tag: main
docker_port: 8001
secrets:
host: ${{secrets.HOST}}
user: ${{secrets.USER}}
private_key: ${{secrets.PRIVATE_KEY}}



27 changes: 27 additions & 0 deletions .github/workflows/deploy_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: deploy

on:
push:
branches:
- 'development'
pull_request:
branches:
- 'development'
types:
- 'closed'

jobs:
deploy_staging:
if: github.event_name == 'push' || github.event.pull_request.merged == true
uses: ./.github/workflows/deploy.yml
with:
envname: staging
docker_tag: latest
docker_port: 8000
secrets:
host: ${{secrets.HOST}}
user: ${{secrets.USER}}
private_key: ${{secrets.PRIVATE_KEY}}



1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ jobs:
VALIDATE_PHP_BUILTIN: false
VALIDATE_PHP_PHPSTAN: false
VALIDATE_PHP_PSALM: false
FILTER_REGEX_EXCLUDE: .*.github/.*

0 comments on commit 0fac720

Please sign in to comment.