Skip to content

dockerize frontend (#90) #43

dockerize frontend (#90)

dockerize frontend (#90) #43

Workflow file for this run

name: pipe
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
DOCKERHUB_USERNAME: veetik
DOCKER_IMAGE_BACKEND: veetik/tasks-backend
DOCKER_IMAGE_FRONTEND: veetik/tasks-frontend
FRONT_API_URL: https://tasks-api.veetik.com
FRONT_VAPID_PUBLIC_KEY: BMvRTtdBaxw8nWOkVbBOH_mC7sPHTkgVbbtrYqEek05-iupcxgkLUksERHvFsBIE5xytDaNzxeuLHTLu8FC-O-k
FRONT_DIR: ./frontend
BACK_DIR: ./backend
jobs:
determine_changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.changes.outputs.backend }}
frontend: ${{ steps.changes.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd
id: changes
with:
filters: |
backend:
- 'backend/**'
frontend:
- 'frontend/**'
check_backend:
runs-on: ubuntu-latest
needs: [determine_changes]
if: needs.determine_changes.outputs.backend == 'true'
defaults:
run:
working-directory: ${{ env.BACK_DIR }}
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@1fbea72663f6d4c03efaab13560c8a24cfd2a7cc
with:
components: rustfmt
- name: check formatting
run: cargo fmt --check
build_and_push_backend_image:
runs-on: ubuntu-latest
needs: [determine_changes]
if: needs.determine_changes.outputs.backend == 'true'
steps:
- uses: actions/checkout@v4
- name: set up QEMU
uses: docker/setup-qemu-action@v3
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: login to docker hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_BACKEND }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
- name: build and push docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ${{ env.BACK_DIR }}
platforms: linux/amd64
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_BACKEND }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE_BACKEND }}:buildcache,mode=max
deploy_backend:
runs-on: ubuntu-latest
needs: [build_and_push_backend_image]
if: github.event_name != 'pull_request'
environment: prod
steps:
- uses: actions/checkout@v4
- name: set up QEMU
uses: docker/setup-qemu-action@v3
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: login to docker hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_BACKEND }}
tags: prod
- name: build and push docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ${{ env.BACK_DIR }}
platforms: linux/amd64
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_BACKEND }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE_BACKEND }}:buildcache,mode=max
- name: update deployment
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ~/tasks && \
docker rollout -f ./docker-compose.yml backend
check_frontend:
runs-on: ubuntu-latest
needs: [determine_changes]
if: needs.determine_changes.outputs.frontend == 'true'
defaults:
run:
working-directory: ${{ env.FRONT_DIR }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- name: install
run: bun install
- name: check formatting
run: bun run formatcheck
- name: typecheck
run: bun run typecheck
- name: lint
run: bun run lint
- name: build
run: bun run build
build_and_push_frontend_image:
runs-on: ubuntu-latest
needs: [determine_changes]
if: needs.determine_changes.outputs.frontend == 'true'
steps:
- uses: actions/checkout@v4
- name: set up QEMU
uses: docker/setup-qemu-action@v3
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: login to docker hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_FRONTEND }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
- name: build and push docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ${{ env.FRONT_DIR }}
platforms: linux/amd64
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_FRONTEND }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE_FRONTEND }}:buildcache,mode=max
build-args: |
API_URL=${{ env.FRONT_API_URL }}
VAPID_PUBLIC_KEY=${{ env.FRONT_VAPID_PUBLIC_KEY }}
deploy_frontend:
runs-on: ubuntu-latest
needs: [build_and_push_frontend_image]
if: github.event_name != 'pull_request'
environment: prod
steps:
- uses: actions/checkout@v4
- name: set up QEMU
uses: docker/setup-qemu-action@v3
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: login to docker hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_FRONTEND }}
tags: prod
- name: build and push docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ${{ env.FRONT_DIR }}
platforms: linux/amd64
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_FRONTEND }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE_FRONTEND }}:buildcache,mode=max
build-args: |
API_URL=${{ env.FRONT_API_URL }}
VAPID_PUBLIC_KEY=${{ env.FRONT_VAPID_PUBLIC_KEY }}
- name: update deployment
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ~/tasks && \
docker rollout -f ./docker-compose.yml frontend