Skip to content

DRAFT: Add Web page interface #1

DRAFT: Add Web page interface

DRAFT: Add Web page interface #1

Workflow file for this run

name: Build and Deploy Docker Image
on:
push:
branches:
- main
- feature/docker*
- feature/add-docker*
pull_request:
branches:
- main
- feature/docker*
- feature/add-docker*
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Check out code
uses: actions/checkout@v3
# Step 2: Set up Node.js 20
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22
cache: 'npm'
# Step 3: Install dependencies
- name: Install dependencies
run: npm install
# Step 4: Build the Docker image using the npm script
- name: Build Docker image
run: |
REPO_NAME=$(echo "${{ github.repository }}" | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]')
docker build -t $REPO_NAME:latest .
# Step 5: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Step 6: Push Docker image with branch-specific tags
- name: Push Docker image with branch-specific tags
run: |
# Get the repository name and transform it into a valid Docker image name
REPO_NAME=$(echo "${{ github.repository }}" | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g')
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME=ghcr.io/$REPO_OWNER/$REPO_NAME
# Sanitize the branch name to be Docker-compatible
SANITIZED_BRANCH_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
# Tag and push the Docker image with branch-specific tags
docker tag $REPO_NAME:latest $IMAGE_NAME:$SANITIZED_BRANCH_NAME
docker push $IMAGE_NAME:$SANITIZED_BRANCH_NAME
# Step 7: Push the 'latest' tag only for the main branch
- name: Push 'latest' tag for main branch
if: github.ref == 'refs/heads/main'
run: |
# Reuse the repository name transformation logic
REPO_NAME=$(echo "${{ github.repository }}" | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g')
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME=ghcr.io/$REPO_OWNER/$REPO_NAME
# Tag and push the Docker image with the 'latest' tag
docker tag $REPO_NAME:latest $IMAGE_NAME:latest
docker push $IMAGE_NAME:latest