Skip to content

Commit 457cf70

Browse files
committed
chore: add gh action to build & push img to gcp
1 parent aaa1f9d commit 457cf70

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and deploy docker image
2+
3+
on: [push]
4+
5+
env:
6+
DATABASE_TYPE: postgresql
7+
SKIP_DB_CHECK: 1
8+
DATABASE_URL: postgresql://umami:umami@db:5432/umami
9+
10+
PROJECT_ID: cocoon-space-web
11+
SERVICE_NAME: cocoon-space-umami
12+
REGION: europe-west1
13+
REGISTRY: europe-west1-docker.pkg.dev
14+
REPOSITORY: cocoon-space
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Authenticate to Google Cloud
24+
uses: google-github-actions/auth@v2
25+
with:
26+
credentials_json: '${{ secrets.RUN_SA_KEY }}'
27+
28+
- name: Set up Google Cloud SDK
29+
uses: google-github-actions/setup-gcloud@v2
30+
31+
- name: Configure Docker for GCP
32+
run: gcloud auth configure-docker ${{ env.REGISTRY }}
33+
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: Build and push
38+
uses: docker/build-push-action@v6
39+
with:
40+
push: true
41+
build-args: |
42+
DATABASE_TYPE=postgresql
43+
tags: |
44+
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}
45+
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:latest
46+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:latest
47+
cache-to: type=inline
48+
49+
- name: Show Output
50+
run: echo ${{ steps.deploy.outputs.url }}

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ COPY --from=builder /app/generated ./generated
5757
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
5858
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
5959

60+
COPY run.sh /run.sh
61+
RUN chmod +x /run.sh
62+
6063
USER nextjs
6164

6265
EXPOSE 3000
6366

6467
ENV HOSTNAME=0.0.0.0
6568
ENV PORT=3000
6669

67-
CMD ["pnpm", "start-docker"]
70+
CMD ["/run.sh"]

run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
if [ -z "$DATABASE_URL" ]; then
4+
DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"
5+
export DATABASE_URL
6+
fi
7+
8+
pnpm start-docker

0 commit comments

Comments
 (0)