Build Docker Image #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Image | |
on: | |
workflow_dispatch: | |
inputs: | |
BUILD_TARGET: | |
type: choice | |
description: Build target | |
options: | |
- "backend" | |
- "frontend" | |
COMMIT_REF: | |
type: string | |
description: Commit reference | |
default: "main" | |
jobs: | |
deploy: | |
runs-on: ubuntu-22.04 | |
environment: "registry-public" | |
permissions: | |
contents: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.COMMIT_REF }} | |
- name: Prepare Environment | |
id: prepare | |
run: | | |
touch .env; rm .env; touch .env | |
RANDOM_TAG=$(openssl rand -hex 4) | |
echo "IMAGE_PREFIX=${{ secrets.REGISTRY_HOST }}/tbscode/django-vike-chat/open-chat-" > .env | |
echo "IMAGE_TAG=$RANDOM_TAG" >> .env | |
echo "RANDOM_TAG=$RANDOM_TAG" >> $GITHUB_OUTPUT | |
- name: Build Image | |
run: | | |
echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ${{ secrets.REGISTRY_HOST }} -u ${{ secrets.REGISTRY_USER }} --password-stdin | |
docker compose -f docker-compose.pro.yaml build ${{ github.event.inputs.BUILD_TARGET }} | |
docker compose -f docker-compose.pro.yaml push ${{ github.event.inputs.BUILD_TARGET }} | |
docker tag ${{ secrets.REGISTRY_HOST }}/tbscode/django-vike-chat/open-chat-${{ github.event.inputs.BUILD_TARGET }}:${{ steps.prepare.outputs.RANDOM_TAG }} ${{ secrets.REGISTRY_HOST }}/tbscode/django-vike-chat/open-chat-${{ github.event.inputs.BUILD_TARGET }}:latest | |
docker push ${{ secrets.REGISTRY_HOST }}/tbscode/django-vike-chat/open-chat-${{ github.event.inputs.BUILD_TARGET }}:latest |