Skip to content

Commit

Permalink
CI- build docker and push it on docker hub V0
Browse files Browse the repository at this point in the history
  • Loading branch information
juliecoust committed Jul 3, 2024
1 parent 0444537 commit 6a2b701
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist/
59 changes: 59 additions & 0 deletions .github/workflows/public.yml
Original file line number Diff line number Diff line change
@@ -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







25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6a2b701

Please sign in to comment.