Skip to content

Commit

Permalink
feat: ad dockerfile & ci for cd
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiluo committed Oct 6, 2024
1 parent 307e8bd commit e81995e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
60 changes: 60 additions & 0 deletions .github/workflows/docker_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker Image CI

on:
push:
branches:
- master
workflow_dispatch:

env:
DEPLOY_NAME: 'vidar-website'
IMAGE_REPO: 'vidar-team/vidar-website'
IMAGE_BASE: 'registry.cn-hangzhou.aliyuncs.com'

jobs:
build:
if: github.repository == 'vidar-team/Vidar-Website'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Gen tag
id: gen-tag
run: |
echo "tag=$(date +%s)" >> $GITHUB_OUTPUT
echo "Generated tag: ${{ steps.gen-tag.outputs.tag }}"
- name: Build the Docker image
run: |
echo "Building Website image with tag: ${{ steps.gen-tag.outputs.tag }}"
docker build --no-cache -f Dockerfile ./blog --tag ${{ env.IMAGE_BASE }}/${{ env.IMAGE_REPO }}-main:${{ steps.gen-tag.outputs.tag }}
- name: Push the Docker image
timeout-minutes: 3
run: |
echo "Logging into Docker registry: ${{ env.IMAGE_BASE }}"
docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.IMAGE_BASE }}
echo "Pushing Website Docker image with tag: ${{ steps.gen-tag.outputs.tag }}"
docker push ${{ env.IMAGE_BASE }}/${{ env.IMAGE_REPO }}-main:${{ steps.gen-tag.outputs.tag }}
- name: Checkout ArgoCD
uses: actions/checkout@v4
with:
repository: vidar-team-devops/argocd
ssh-key: ${{ secrets.ARGO_KEY_SSH }}
path: deploy

# - name: Update ArgoCD
# run: |
# cd deploy/tutu
# git config user.name github-actions
# git config user.email [email protected]
# sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./tutu/tutu-deployment.yml
# sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./rsa-web-api/rsa-web-api-deployment.yml
# sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./blog-mysql/blog-mysql-deployment.yml
# git add .
# git commit -m "update: image"
# git push

29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:22-bookworm AS dep-builder

WORKDIR /app

# place ARG statement before RUN statement which need it to avoid cache miss
ARG USE_CHINA_NPM_REGISTRY=1
RUN \
set -ex && \
if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
echo 'use npm mirror' && \
npm config set registry https://registry.npmmirror.com && \
yarn config set registry https://registry.npmmirror.com; \
fi;

COPY ./yarn.lock /app/
COPY ./package.json /app/
COPY ./poi.config.js /app/
COPY ./public /app/public
COPY ./src /app/src

RUN \
set -ex && \
ls && \
yarn

Run \
set -ex && \
cd /app/ && \
yarn build
1 change: 0 additions & 1 deletion tmp/test

This file was deleted.

0 comments on commit e81995e

Please sign in to comment.