From 03ba15148f63f92254cbac6b969395210d9c3975 Mon Sep 17 00:00:00 2001 From: Shoma097 Date: Mon, 22 Sep 2025 14:16:16 +0800 Subject: [PATCH 1/2] added Git Action for Docker --- .github/workflows/build-docker.yaml | 16 ++++++++++++++++ api/Dockerfile | 11 +++++++++++ front-end-nextjs/Dockerfile | 20 ++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 .github/workflows/build-docker.yaml create mode 100644 api/Dockerfile create mode 100644 front-end-nextjs/Dockerfile diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml new file mode 100644 index 00000000..36b8f734 --- /dev/null +++ b/.github/workflows/build-docker.yaml @@ -0,0 +1,16 @@ +name: build publish image to docker to DockerHub +on: + [workflow_dispatch] + +jobs: + publish_images: + runs-on: ubunntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: build image + run: docker build ./api/ -t zennnnnnnnnn/devops-qr-code-api:latest + - name: push image to DockerHub + run: | + dockerpush zennnnnnnnnn/devops-qr-code-api:latest + diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 00000000..efa73973 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.9 + +WORKDIR /usr/src/app + +COPY requirements.txt ./ + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80" ] \ No newline at end of file diff --git a/front-end-nextjs/Dockerfile b/front-end-nextjs/Dockerfile new file mode 100644 index 00000000..1ace9d51 --- /dev/null +++ b/front-end-nextjs/Dockerfile @@ -0,0 +1,20 @@ +FROM node:18-alpine AS base + +WORKDIR /app + +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ + +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi + +COPY . . + +RUN npm run build + +EXPOSE 3000 + +CMD ["npm", "start"] \ No newline at end of file From fcb2bdc5ce7051b377b142096f701a7ab3797265 Mon Sep 17 00:00:00 2001 From: Shoma097 Date: Mon, 22 Sep 2025 15:01:31 +0800 Subject: [PATCH 2/2] Update build-docker workflow --- .github/workflows/build-docker.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml index 36b8f734..f4d06f41 100644 --- a/.github/workflows/build-docker.yaml +++ b/.github/workflows/build-docker.yaml @@ -4,7 +4,7 @@ on: jobs: publish_images: - runs-on: ubunntu-latest + runs-on: ubuntu-latest steps: - name: checkout uses: actions/checkout@v4 @@ -12,5 +12,5 @@ jobs: run: docker build ./api/ -t zennnnnnnnnn/devops-qr-code-api:latest - name: push image to DockerHub run: | - dockerpush zennnnnnnnnn/devops-qr-code-api:latest + docker push zennnnnnnnnn/devops-qr-code-api:latest