-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a base image to speed up builds
- Loading branch information
=
committed
Nov 16, 2024
1 parent
92dc8ff
commit d234c22
Showing
6 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (c) 2024 Isaac Adams | ||
# Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
name: Build Base Image | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '.github/**' | ||
- 'seeds/**' | ||
- 'dump/**' | ||
- 'k8s/**' | ||
- '!Base.Dockerfile' | ||
- '!requirements.txt' | ||
- '!package-lock.json' | ||
- '.gitignore' | ||
|
||
concurrency: | ||
group: deployment | ||
|
||
env: | ||
PROJECT_ID: crank-404520 | ||
SERVICE: crank | ||
REGION: us-west1 | ||
ARTIFACT_REPO: crank-repository | ||
|
||
jobs: | ||
build-base-image: | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
packages: 'write' | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check if last commit was a merge commit | ||
id: check | ||
run: | | ||
if [[ "$(git log --merges -1 --pretty=%H)" != "$(git log -1 --pretty=%H)" ]]; then | ||
echo "This was not a merge commit. Exiting..." | ||
exit 1 | ||
fi | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Install Node.js dependencies | ||
run: npm install | ||
|
||
- name: Authenticate with GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Copy Base.Dockerfile to Dockerfile | ||
run: | | ||
cp Base.Dockerfile Dockerfile | ||
- name: Build and Push Container to GitHub Container Registry | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ghcr.io/${{ github.repository }}/crank-base:${{ github.sha }} | ||
|
||
- name: Tag and Push Image as Latest | ||
run: | | ||
docker tag ghcr.io/${{ github.repository }}/crank-base:${{ github.sha }} ghcr.io/${{ github.repository }}/crank-base:latest | ||
docker push ghcr.io/${{ github.repository }}/crank-base:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.13.0-alpine3.20 | ||
|
||
# create a non-root user to run the app as | ||
RUN addgroup -S appgroup -g 10000 | ||
RUN adduser -S appuser -u 10000 -G appgroup | ||
|
||
# Set the working directory in the container to /app | ||
WORKDIR /app | ||
|
||
# Add current directory code to /app in container | ||
ADD . /app | ||
|
||
COPY .env-prod .env | ||
|
||
# fixing busybox vulnerabilities identified by synk | ||
RUN apk add --no-cache --upgrade busybox | ||
RUN apk add --no-cache busybox-extras | ||
|
||
RUN apk add --no-cache --virtual build-deps gcc musl-dev libffi-dev pkgconf mariadb-dev | ||
RUN apk add --no-cache mariadb-connector-c-dev | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN apk del build-deps | ||
|
||
# Install Node.js and npm | ||
RUN apk update | ||
RUN apk add nodejs npm | ||
|
||
# Install npm dependencies | ||
RUN npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters