Skip to content

Commit

Permalink
add action
Browse files Browse the repository at this point in the history
  • Loading branch information
mariovyord committed Dec 13, 2023
1 parent 8bc88c3 commit 9589068
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/image.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: image-ci

on:
push:
branches:
- "main"
tags:
- "v*"

jobs:
build-tag-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
mariovyordanov/api-node
tags: |
type=raw,value=latest
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value={{date 'YYYYMMDD'}}-{{sha}}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
file: ./Dockerfile
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "mariovyordanov/api-node:latest"
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL"
18 changes: 0 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory (better layer caching)
COPY package*.json ./

FROM base as dev

# Install dependencies
RUN --mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm install

# Copy all local files to the working directory
COPY . .

# Build the TypeScript files
RUN npm run build

# Command to run the app
CMD ["npm", "run", "dev"]

FROM base as production

# Set NODE_ENV
ENV NODE_ENV production

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ TEST_COMPOSE_FILE=docker-compose-test.yml

### DOCKER COMPOSE COMMANDS

.PHONY: prod-compose-build
prod-compose-build:
docker compose -f $(PROD_COMPOSE_FILE) build

.PHONY: compose-build
compose-build:
docker compose -f $(DEV_COMPOSE_FILE) build
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: "3"

services:
app:
image: mariovyordanov/api-node
build:
context: .
dockerfile: ./Dockerfile
target: production
ports:
- "5000:5000"
networks:
Expand Down

0 comments on commit 9589068

Please sign in to comment.