Skip to content

Add build yaml #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Docker Build CI/CD

on:
pull_request:
branches:
- main

env:
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GAR_LOCATION: asia-northeast3
PROJECT_ID: o1labs-192920
REGISTRY: gitops-images

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout PR branch
run: |
git fetch origin ${{github.event.pull_request.head.ref}}
git checkout ${{github.event.pull_request.head.sha}}

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Authenticate to Google Cloud
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ env.GCP_SA_KEY }}

- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev

- name: Determine tags
id: determine_tags
run: |
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
FULL_TAG="${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REGISTRY }}/archive-node-api:dev-${{ github.sha }}"
SHORT_TAG="${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REGISTRY }}/archive-node-api:dev-${SHORT_SHA}"
echo "tags=${FULL_TAG},${SHORT_TAG}" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.determine_tags.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build the TypeScript code
FROM node:18-alpine as build
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
Expand Down