From 42d89ed844b8f1ae12444d7fc3979261e7d8901e Mon Sep 17 00:00:00 2001 From: DrunkBatya Date: Wed, 26 Jul 2023 11:58:30 +0300 Subject: [PATCH] Improove CI/CD --- .github/workflows/deploy.yml | 66 +++++++++++++++++++++++------------- Dockerfile | 5 +-- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6474244..a2fc0a4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,43 +1,61 @@ -name: Deploy +name: 'Deploy' on: push: branches: - - main - dev + tags: + - '*' jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: 'Checkout code' + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - images: ghcr.io/flipperdevices/flpr.app - flavor: latest=${{ github.ref == 'refs/heads/main' }} - tags: type=ref,event=branch - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + + - name: 'Set image tag' + id: tag + run: | + IMAGE_TAG="0.0.0" + if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + REF=${{ github.ref }}; + TAG_FULL=${REF#refs/*/}; + IMAGE_TAG=${TAG_FULL//\//_}; + fi + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV + echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT + + - name: 'Set up QEMU' + uses: docker/setup-qemu-action@v2 + + - name: 'Set up Docker Buildx' + uses: docker/setup-buildx-action@v2 + + - name: 'Login to GHCR' + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.CR_PAT }} - - name: Build and push + + - name: 'Build and push' id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: - context: . push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + tags: ghcr.io/flipperdevices/flpr.app:${{steps.tag.outputs.image_tag}} + + - name: 'Image digest' + run: | + echo ${{ steps.docker_build.outputs.digest }} + + - name: 'Trigger k8s to use new image' + uses: peter-evans/repository-dispatch@v2 + with: + repository: ${{ secrets.INFRASTRUCTURE_REPO }} + token: ${{ secrets.K8S_GITHUB_PAT }} + event-type: flpr-app-deploy + client-payload: '{"image_tag": "${{steps.tag.outputs.image_tag}}"}' diff --git a/Dockerfile b/Dockerfile index 3315abb..e4b8a9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,3 @@ -FROM nginx -COPY frontend/ /usr/share/nginx/html \ No newline at end of file +FROM nginx:1.25.1-alpine + +COPY frontend/ /usr/share/nginx/html