Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build and push docker image

on: [push]
on:
push:
workflow_dispatch:

env:
DOCKER_REPO: ${{ secrets.DOCKER_USERNAME }}/hawk-garage
Expand All @@ -12,13 +14,31 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Compute deploy tag
- name: Prepare deploy tag
id: deploy
shell: bash
run: |
set -euo pipefail

case "${GITHUB_REF_NAME}" in
stage|prod|prod-ru)
echo "is_deploy=true" >> "$GITHUB_OUTPUT"
echo "tag=${GITHUB_REF_NAME}-${GITHUB_SHA::7}-$(date +%s)" >> "$GITHUB_OUTPUT"
;;
*)
echo "is_deploy=false" >> "$GITHUB_OUTPUT"
echo "tag=" >> "$GITHUB_OUTPUT"
;;
esac

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22

- name: Make stage envfile
if: endsWith(github.ref, '/stage')
if: github.ref_name == 'stage'
uses: SpicyPizza/create-envfile@v1
with:
envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }}
Expand All @@ -32,7 +52,7 @@ jobs:
# envkey_VITE_API_ENDPOINT: "https://api.stage.hawk.so"

- name: Make prod envfile
if: endsWith(github.ref, '/prod')
if: github.ref_name == 'prod'
uses: SpicyPizza/create-envfile@v1
with:
envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }}
Expand All @@ -41,8 +61,8 @@ jobs:
envkey_VITE_API_ENDPOINT: "https://api.hawk.so"
envkey_VITE_FREE_PLAN_ID: ${{ secrets.FREE_PLAN_ID }}

- name: Make prod envfile
if: endsWith(github.ref, '/prod-ru')
- name: Make prod-ru envfile
if: github.ref_name == 'prod-ru'
uses: SpicyPizza/create-envfile@v1
with:
envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }}
Expand All @@ -55,6 +75,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: steps.deploy.outputs.is_deploy == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand All @@ -69,11 +90,22 @@ jobs:
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ startsWith(github.ref, 'refs/heads') }}
type=raw,value=${{ steps.deploy.outputs.tag }},enable=${{ steps.deploy.outputs.is_deploy == 'true' }}

- name: Build and push production image
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
push: ${{ endsWith(github.ref, '/stage') || endsWith(github.ref, '/prod') || endsWith(github.ref, '/prod-ru') }}
push: ${{ steps.deploy.outputs.is_deploy == 'true' }}

- name: Send docker tag to chat
if: ${{ success() && steps.deploy.outputs.is_deploy == 'true' }}
uses: codex-team/action-codexbot-notify@v1
with:
webhook: ${{ secrets.CODEXBOT_NOTIFY_WEBHOOK }}
parse_mode: HTML
disable_web_page_preview: true
message: |
<b>Docker tag</b>: <code>${{ steps.deploy.outputs.tag }}</code>
<b>Image</b>: <code>${{ env.DOCKER_REPO }}:${{ steps.deploy.outputs.tag }}</code>
Loading
Loading