updated styles #49
This file contains hidden or 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
# This is a workflow to build a Docker image and deploy it to Docker Hub | |
name: Docker CI/CD | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the "main" branch | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
env: | |
PROJECT_NAME: utilplex | |
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | |
DOCKER_HUB_REPOSITORY: ${{ vars.DOCKER_HUB_REPOSITORY || 'utilplex' }} | |
IMAGE_TAG: ${{ github.sha }} | |
jobs: | |
build: | |
name: Build and test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node 18.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build:ci | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and export Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
load: true | |
tags: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
- name: Test Docker image | |
run: | | |
docker run --rm ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }} echo "Docker image built successfully" | |
- name: Archive build | |
if: success() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: docker_meta | |
path: | | |
.docker/ | |
Dockerfile | |
docker-compose.yml | |
if-no-files-found: ignore | |
deploy: | |
name: Deploy to Docker Hub | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.event_name != 'pull_request' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: docker_meta | |
path: . | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:latest |