Skip to content

Commit

Permalink
Create manual-dev-build.yaml (#285)
Browse files Browse the repository at this point in the history
* Create manual-dev-build.yaml

* Update manual-dev-build.yaml

* Update manual-dev-build.yaml

* Update manual-dev-build.yaml

* Added workflow dispatch

* Updated action dispatch

* Added ref

* Set workflow name

* Add deploy step

* Run build on pr

* Merge into dev

* Added test workflow

* Removed needs

* Update user secret

* Updated workflows to use dev

* Updated workflows to use dev

* Update manaul workflow
  • Loading branch information
JElgar authored Oct 4, 2021
1 parent 05aa6ef commit fecf5f5
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 51 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build, push, deploy

on:
push:
branches: [dev, main]

env:
IMAGE_NAME: api
IMAGE_OWNER: bristolsta

SERVICE_NAME: "${{ github.ref == 'refs/heads/main' && 'uobtheatre-api' || 'uobtheatre-api-staging' }}"

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file compose/production/django/Dockerfile --tag ghcr.io/$IMAGE_OWNER/$IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log into registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.BRISTOLSTA_REGISTRY_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: docker push ghcr.io/$IMAGE_OWNER/$IMAGE_NAME:latest

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy new image
uses: appleboy/ssh-action@master
env:
SERVICE_NAME: $SERVICE_NAME
with:
host: ${{ secrets.SERVER_SSH_HOST }}
username: ${{ secrets.SERVER_SSH_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_SSH_PORT }}
envs: SERVICE_NAME
script: |
cd /var/sta
docker-compose pull $SERVICE_NAME
docker-compose up -d $SERVICE_NAME
docker-compose exec $SERVICE_NAME python manage.py migrate
32 changes: 32 additions & 0 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Dev image build and push

on:
push:
branches:
- dev

workflow_dispatch:

env:
DEV_IMAGE_NAME: api-dev
IMAGE_OWNER: bristolsta

jobs:
build-dev:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file compose/local/django/Dockerfile --tag ghcr.io/$IMAGE_OWNER/$DEV_IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log into registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.BRISTOLSTA_REGISTRY_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: docker push ghcr.io/$IMAGE_OWNER/$DEV_IMAGE_NAME:latest
51 changes: 0 additions & 51 deletions .github/workflows/docker-build.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/manual-dev-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Trigger dev build

on:
pull_request:
types: [opened]
issue_comment:
types: [created]

jobs:
trigger-deploy:
runs-on: ubuntu-latest
steps:
- uses: khan/pull-request-comment-trigger@master
id: check
with:
trigger: '!build-dev'
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: Invoke workflow without inputs
uses: benc-uk/workflow-dispatch@v1
if: steps.check.outputs.triggered == 'true'
with:
workflow: Dev image build and push
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}

0 comments on commit fecf5f5

Please sign in to comment.