Skip to content

Commit

Permalink
Merge pull request #187 from lilla-nemeth/feature/create-github-workf…
Browse files Browse the repository at this point in the history
…low-to-push-docker-images

Feature/create GitHub workflow to push docker images
  • Loading branch information
lilla-nemeth authored Mar 31, 2024
2 parents f59755c + 6b6c28b commit 2486840
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
30 changes: 13 additions & 17 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Lost and Found NodeJS CI
name: Node.js CI with Tests

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

defaults:
run:
working-directory: server

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Run Yarn
run: yarn
- name: Run tests
run: yarn test
- name: Checkout repository
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Run Yarn
run: yarn
- name: Run tests
run: yarn test
50 changes: 50 additions & 0 deletions .github/workflows/publish-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Docker Image CI for Github Container Registry

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build_and_publish:
runs-on: ubuntu-latest
env:
PG_PASSWORD: ${{ secrets.PG_PASSWORD }}
PG_DATABASE: ${{ secrets.PG_DATABASE }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: ~/.docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}

- name: Build and push Docker image
run: |
# Build and push PostgreSQL service image
docker pull postgres:16.1
docker tag postgres:16.1 ghcr.io/${{ github.repository_owner }}/postgres:16.1
docker push ghcr.io/${{ github.repository_owner }}/postgres:16.1
# Build and push Server service image
docker-compose -f docker-compose.yml build server
docker tag lost-and-found-server-dev:tag-v1.0.0 ghcr.io/${{ github.repository_owner }}/lost-and-found-server-dev:tag-v1.0.0
docker push ghcr.io/${{ github.repository_owner }}/lost-and-found-server-dev:tag-v1.0.0
# Build and push Client service image
docker-compose -f docker-compose.yml build client
docker tag lost-and-found-client-dev:tag-v1.0.0 ghcr.io/${{ github.repository_owner }}/lost-and-found-client-dev:tag-v1.0.0
docker push ghcr.io/${{ github.repository_owner }}/lost-and-found-client-dev:tag-v1.0.0
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore": ["**/*.yml", "**/*.yaml"]
}
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"

services:
postgres:
Expand All @@ -17,7 +17,7 @@ services:
server:
container_name: lost_and_found_server
restart: unless-stopped
image: lost-and-found-server-dev:1.0.0
image: lost-and-found-server-dev:tag-v1.0.0
build:
context: server
dockerfile: Dockerfile
Expand All @@ -31,7 +31,7 @@ services:
client:
container_name: lost_and_found_client
restart: unless-stopped
image: lost-and-found-client-dev:1.0.0
image: lost-and-found-client-dev:tag-v1.0.0
build:
context: client
dockerfile: Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getAllUsers } from '../controllers/userControllers';
const router = Router();

router.get('/', authMw, getAllUsers);
router.get('/pets/:fetch/:skip', getPetsByPagination);
router.get('/pets/:id', getPetById);
router.get('/pets/:fetch/:skip', getPetsByPagination);

export default router;

0 comments on commit 2486840

Please sign in to comment.