From c2fe81a58b3aacf644b2f91b5558d7632a02628a Mon Sep 17 00:00:00 2001 From: thongdanghoang Date: Wed, 12 Jun 2024 10:58:10 +0700 Subject: [PATCH] release: 1.0.0 --- .github/workflows/docker.yml | 67 +++++++++++++++++++ docke-compose.yml | 2 + frontend/.gitignore | 3 +- frontend/Dockerfile | 13 ++++ frontend/package.json | 3 +- frontend/src/App.tsx | 2 +- resource-server/Dockerfile | 21 ++++++ .../fptu/swp391/shoppingcart/MainTests.java | 13 ---- 8 files changed, 108 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 frontend/Dockerfile delete mode 100644 resource-server/src/test/java/fptu/swp391/shoppingcart/MainTests.java diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..aa7a12d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,67 @@ +name: ci + +on: + push: + branches: + - "release/*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - name: Extract version from branch name + run: echo "VERSION=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_ENV + - name: Set up JDK 11 for x64 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + architecture: x64 + - name: Build with Maven + run: cd resource-server && mvn --batch-mode --update-snapshots verify + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + - run: cd frontend && npm i + - run: cd frontend && npm run build + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Build and push backend + uses: docker/build-push-action@v5 + with: + context: ./resource-server + file: ./resource-server/Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: "${{ secrets.DOCKERHUB_USERNAME }}/isc-301-services:${{ env.VERSION }}" + build-args: | + MYSQL_USER=${{ secrets.MYSQL_USER }} + MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} + MAILGUN_DOMAIN_NAME=${{ secrets.MAILGUN_DOMAIN_NAME }} + MAILGUN_API_KEY=${{ secrets.MAILGUN_API_KEY }} + TWILIO_ACCOUNT_SID=${{ secrets.TWILIO_ACCOUNT_SID }} + TWILIO_AUTH_TOKEN=${{ secrets.TWILIO_AUTH_TOKEN }} + TWILIO_SERVICE_SID=${{ secrets.TWILIO_SERVICE_SID }} + GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} + GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} + - + name: Build and push frontend + uses: docker/build-push-action@v5 + with: + context: ./frontend + file: ./frontend/Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: "${{ secrets.DOCKERHUB_USERNAME }}/isc-301-web:${{ env.VERSION }}" \ No newline at end of file diff --git a/docke-compose.yml b/docke-compose.yml index d34d439..57804ed 100644 --- a/docke-compose.yml +++ b/docke-compose.yml @@ -2,6 +2,7 @@ version: "3.9" services: # mysql database mysql-db: + container_name: n3tk-db image: mysql:latest environment: MYSQL_ROOT_PASSWORD: root @@ -10,6 +11,7 @@ services: - "3306:3306" # spring boot app spring-boot-app: + container_name: n3tk-app build: resource-server environment: MYSQL_USER: ${MYSQL_USER} diff --git a/frontend/.gitignore b/frontend/.gitignore index bdcde88..8c62d2a 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -37,4 +37,5 @@ npm-debug.log yarn-error.log # React related -/build/ \ No newline at end of file +/build/ +dist \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..aeca386 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,13 @@ +FROM nginx:alpine + +# Copy custom configuration file from the current directory +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Remove default nginx static assets +RUN rm -rf /usr/share/nginx/html/* + +# Copy static assets from builder stage +COPY dist /usr/share/nginx/html + +# Containers run nginx with global directives and daemon off +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index fc6ed03..430ec75 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,8 @@ { "name": "react", "private": true, - "version": "0.0.0", + "version": "1.0.0", + "homepage": "/isc-301", "type": "module", "scripts": { "dev": "vite --port 3000", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f79c5be..6acaeda 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -109,7 +109,7 @@ function App() { },[order.orderItems]) return ( - + {routes.map((route) => { const Page = route.page diff --git a/resource-server/Dockerfile b/resource-server/Dockerfile index 54d8156..5a3314c 100644 --- a/resource-server/Dockerfile +++ b/resource-server/Dockerfile @@ -1,3 +1,24 @@ FROM openjdk:11 AS runstage +FROM openjdk:11 AS runstage +ARG MYSQL_USER +ARG MYSQL_PASSWORD +ARG MAILGUN_DOMAIN_NAME +ARG MAILGUN_API_KEY +ARG TWILIO_ACCOUNT_SID +ARG TWILIO_AUTH_TOKEN +ARG TWILIO_SERVICE_SID +ARG GOOGLE_CLIENT_ID +ARG GOOGLE_CLIENT_SECRET +ENV MYSQL_USER=$MYSQL_USER +ENV MYSQL_PASSWORD=$MYSQL_PASSWORD +ENV MAILGUN_DOMAIN_NAME=$MAILGUN_DOMAIN_NAME +ENV MAILGUN_API_KEY=$MAILGUN_API_KEY +ENV TWILIO_ACCOUNT_SID=$TWILIO_ACCOUNT_SID +ENV TWILIO_AUTH_TOKEN=$TWILIO_AUTH_TOKEN +ENV TWILIO_SERVICE_SID=$TWILIO_SERVICE_SID +ENV GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID +ENV GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET +COPY target/*.jar app.jar +ENTRYPOINT ["java", "-jar", "/app.jar"] COPY target/*.jar app.jar ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/resource-server/src/test/java/fptu/swp391/shoppingcart/MainTests.java b/resource-server/src/test/java/fptu/swp391/shoppingcart/MainTests.java deleted file mode 100644 index cd8018b..0000000 --- a/resource-server/src/test/java/fptu/swp391/shoppingcart/MainTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package fptu.swp391.shoppingcart; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class MainTests { - - @Test - void contextLoads() { - } - -}