Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakovri authored Nov 14, 2022
1 parent 69f3c44 commit 2f469ad
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Build, publish and deploy docker
on:
push:
branches: ['main']
tags:
- 'v*'

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -32,11 +34,100 @@ jobs:
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

tags: |
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=test,enable=true
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy-testing:
name: Deploy Testing
needs: build-and-push-image
runs-on: [self-hosted, Linux]
environment:
name: Testing
url: https://printer.api.test.profcomff.com/
env:
CONTAITER_NAME: com_profcomff_api_printer_test
permissions:
packages: read

steps:
- name: Pull new version
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test

- name: Migrate DB
run: |
docker run \
--rm \
--network=web \
--env DB_DSN=${{ secrets.DB_DSN }} \
--name ${{ env.CONTAITER_NAME }}_migration \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test \
alembic upgrade head
- name: Run new version
id: run_test
run: |
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
docker run \
--detach \
--restart on-failure:3 \
--network=web \
--volume com_profcomff_api_printer_test_static:/app/static \
--env DB_DSN=${{ secrets.DB_DSN }} \
--env SECRET_KEY='${{ secrets.SECRET_KEY }}' \
--env ROOT=https://printer.api.test.profcomff.com/ \
--env PIN_SYMBOLS=0123456789 \
--env PIN_LENGTH=8 \
--env ALLOW_STUDENT_NUMBER=true \
--name ${{ env.CONTAITER_NAME }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
deploy-production:
name: Deploy Production
needs: build-and-push-image
if: startsWith(github.ref, 'refs/tags/v')
runs-on: [self-hosted, Linux]
environment:
name: Production
url: https://printer.api.profcomff.com/
env:
CONTAITER_NAME: com_profcomff_api_printer
permissions:
packages: read

steps:
- name: Pull new version
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

- name: Migrate DB
run: |
docker run \
--rm \
--network=web \
--env DB_DSN=${{ secrets.DB_DSN }} \
--name ${{ env.CONTAITER_NAME }}_migration \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
alembic upgrade head
- name: Run new version
id: run_test
run: |
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
docker run \
--detach \
--restart always \
--network=web \
--volume com_profcomff_api_printer_static:/app/static \
--env DB_DSN='${{ secrets.DB_DSN }}' \
--env SECRET_KEY='${{ secrets.SECRET_KEY }}' \
--env ROOT=https://printer.api.profcomff.com/ \
--env PIN_SYMBOLS=0123456789 \
--env PIN_LENGTH=8 \
--env ALLOW_STUDENT_NUMBER=true \
--name ${{ env.CONTAITER_NAME }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

0 comments on commit 2f469ad

Please sign in to comment.