Skip to content

Commit

Permalink
feat(ci): add workflow, fix dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
nevivurn committed Aug 17, 2024
1 parent 6ab3c17 commit 98c68bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
49 changes: 30 additions & 19 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
name: Build and push
name: Build and push image

on:
push:
branches:
- 'master'
pull_request:
branches:
- 'master'
- master

permissions:
contents: read
id-token: write
packages: write

jobs:
build:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.vars.outputs.image-tag }}
application: ${{ steps.vars.outputs.application }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set variables
id: vars
env:
EVENT_NAME: ${{ github.event_name }}
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
GIT_SHA: ${{ github.sha }}
run: |
date="$(date -u +%Y%m%d)"
short_rev="$(git rev-parse --short "$GIT_SHA")"
echo "image-tag=${REF_NAME}" >> $GITHUB_OUTPUT
echo "application=bacchus-snu/snucse-api" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub container registry
uses: docker/login-action@v2
- name: Configure registry credentials
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/snucse/snucse-api
tags: |
type=ref,event=branch
type=ref,event=pr
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
tags: ghcr.io/bacchus-snu/${{ vars.IMAGE_NAME }}:${{ steps.vars.outputs.image-tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ WORKDIR /app
COPY Gemfile .
COPY Gemfile.lock .
RUN bundle install
RUN apt update && apt install imagemagick -y && rm -rf /var/lib/apt/lists/*
COPY . .
RUN useradd -ms /bin/bash snucse
RUN chown -R snucse: /app
USER snucse
CMD ["passenger", "start"]

0 comments on commit 98c68bc

Please sign in to comment.