diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d26c746 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +dist/ \ No newline at end of file diff --git a/.github/workflows/public.yml b/.github/workflows/public.yml new file mode 100644 index 0000000..e3c236d --- /dev/null +++ b/.github/workflows/public.yml @@ -0,0 +1,59 @@ +name: Build and Push Docker Image - CI + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Create env file + run: | + touch .env + echo ACCESS_TOKEN_SECRET = access_secret >> .env + echo REFRESH_TOKEN_SECRET = refresh_secret >> .env + cat .env + + - name: Build the project + run: npm run prod:build + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64,linux/arm64 + context: . + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/your-image-name:latest + + + + + + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c429c92 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +#Build stage +FROM node:20 AS build + +WORKDIR /src + +COPY package*.json . + +RUN npm install + +COPY . . + +RUN npm run prod:build + +#Production stage +FROM node:20 AS production + +WORKDIR /src + +COPY package*.json . + +RUN npm ci --only=production + +COPY --from=build /src/dist ./dist + +CMD ["node", "dist/main.js"] diff --git a/package.json b/package.json index b26ede2..b7005e8 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,16 @@ "name": "ecopart_back", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "main.js", "scripts": { "test": "jest --watchAll --collectCoverage", "test-CI": "jest --collectCoverage", - "clean": "rimraf dist/*", + "clean": "rimraf ./dist", "copy-assets": "ts-node tools/copyAssets", "tsc": "tsc", + "prod:build": "npm-run-all clean tsc copy-assets", + "prod:serve": "node dist/main.js", + "prod:start": "npm run build && node dist/main.js", "dev:build": "npm-run-all clean tsc copy-assets", "dev:serve": "nodemon -e js -w dist dist/main.js", "dev:watch": "nodemon --watch './**/*.ts' --exec 'ts-node' src/main.ts"