Skip to content

Commit

Permalink
feat: add Dockerfile / image build workflow on fastify OAuth2 app
Browse files Browse the repository at this point in the history
  • Loading branch information
CynicDog committed Dec 27, 2024
1 parent d7add19 commit 75d0b64
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/7_auth_7_2_fastify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: 7_auth_7_2_fastify

on:
push:
branches:
- master
paths:
- 7_auth/7_2_fastify/**
workflow_dispatch:

env:
APP_NAME: auth_fastify
PROJECT_DIR: 7_auth/7_2_fastify

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]

- id: lower-credentials
name: Lower Credentials
run: |
echo "actor=${GITHUB_ACTOR@L}" >> $GITHUB_OUTPUT
echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ steps.lower-credentials.outputs.actor }}
password: ${{ secrets.GHCR_PAT }}

- name: Build Docker image
run: |
cd ${{ env.PROJECT_DIR }} && \
docker build \
--build-arg CLIENT_ID=${{ secrets.OAUTH_GITHUB_CLIENT_ID }} \
--build-arg CLIENT_SECRET=${{ secrets.OAUTH_GITHUB_CLIENT_SECRET }} \
-t ghcr.io/${{ steps.lower-credentials.outputs.repository }}/${{ env.APP_NAME }}:latest .
- name: Push Docker image to GHCR
run: |
docker push ghcr.io/${{ steps.lower-credentials.outputs.repository }}/${{ env.APP_NAME }}:latest
31 changes: 31 additions & 0 deletions 7_auth/7_2_fastify/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build stage
FROM node:18-alpine AS build

# Set working directory
WORKDIR /app

# Copy package files and install dependencies
COPY package*.json ./
RUN npm install --production

# Copy the application source code
COPY . .

# Production stage
FROM node:18-alpine

WORKDIR /app

ARG CLIENT_ID
ARG CLIENT_SECRET
ENV CLIENT_ID=${CLIENT_ID}
ENV CLIENT_SECRET=${CLIENT_SECRET}

# Copy only the necessary files from the build stage
COPY --from=build /app ./

# Expose the port the app will run on
EXPOSE 3000

# Start the Fastify application
CMD ["npm", "run", "start"]

0 comments on commit 75d0b64

Please sign in to comment.