Skip to content

Commit d8fefb6

Browse files
authored
added auth service (#58)
1 parent 07edeba commit d8fefb6

File tree

20 files changed

+1972
-26
lines changed

20 files changed

+1972
-26
lines changed

.github/workflows/build-auth.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Push Auth
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- 'auth/**'
10+
- '.github/workflows/build-auth.yaml'
11+
release:
12+
types: [published]
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
17+
jobs:
18+
build-auth:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v2
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ github.repository }}-auth
42+
tags: |
43+
type=pep440,pattern={{version}},value=${{ github.ref_name }},enable=${{ github.event_name == 'release' }}
44+
type=ref,event=branch
45+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
46+
47+
- name: Build and Push Docker image
48+
uses: docker/build-push-action@v4
49+
with:
50+
context: ./auth
51+
dockerfile: Dockerfile
52+
push: true
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Docker Image
1+
name: Build and Push Backend
22

33
on:
44
push:
@@ -7,22 +7,20 @@ on:
77
- dev
88
paths:
99
- 'scribbl_backend/**'
10-
- '.github/workflows/build-and-push.yaml'
10+
- '.github/workflows/build-backend.yaml'
1111
release:
1212
types: [published]
13+
1314
env:
1415
REGISTRY: ghcr.io
15-
IMAGE_NAME: ${{ github.repository }}-backend
1616

1717
jobs:
18-
build-and-push:
18+
build-backend:
1919
runs-on: ubuntu-latest
20-
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
2120
permissions:
2221
contents: read
2322
packages: write
2423
steps:
25-
2624
- name: Checkout code
2725
uses: actions/checkout@v2
2826

@@ -40,22 +38,19 @@ jobs:
4038
id: meta
4139
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
4240
with:
43-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
images: ${{ env.REGISTRY }}/${{ github.repository }}-backend
4442
tags: |
45-
# minimal
4643
type=pep440,pattern={{version}},value=${{ github.ref_name }},enable=${{ github.event_name == 'release' }}
47-
# branch event
4844
type=ref,event=branch
4945
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
5046
5147
- name: Build and Push Docker image
5248
uses: docker/build-push-action@v4
5349
with:
54-
# build-args:
5550
context: ./scribbl_backend
5651
dockerfile: Dockerfile
5752
push: true
5853
cache-from: type=gha
5954
cache-to: type=gha,mode=max
6055
tags: ${{ steps.meta.outputs.tags }}
61-
labels: ${{ steps.meta.outputs.labels }}
56+
labels: ${{ steps.meta.outputs.labels }}

auth/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Binaries
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
*.test
8+
auth-service
9+
10+
# Output of the go coverage tool, specifically when used with LiteIDE
11+
*.out
12+
13+
# Dependency directories (vendor/)
14+
vendor/
15+
16+
# IDE/editor files
17+
.vscode/
18+
.idea/
19+
*.swp
20+
21+
# OS files
22+
.DS_Store
23+
Thumbs.db
24+
25+
# Environment files
26+
.env
27+
.env.*
28+
29+
# Docker
30+
*.log
31+
docker-compose.override.yml
32+
33+
# Test cache
34+
go-test-cache/

auth/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# syntax=docker/dockerfile:1
2+
FROM golang:1.23-alpine AS builder
3+
4+
# Install git for private repos and ca-certificates for HTTPS
5+
RUN apk update && apk add --no-cache git ca-certificates
6+
7+
WORKDIR /app
8+
9+
# Copy go mod files and download dependencies first (better caching)
10+
COPY go.mod go.sum ./
11+
RUN go mod download && go mod verify
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Build the application with optimizations
17+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
18+
-ldflags='-w -s -extldflags "-static"' \
19+
-o auth-service ./cmd/auth/main.go
20+
21+
# Final stage - minimal Alpine image
22+
FROM alpine:3.21
23+
24+
# Install CA certificates for HTTPS
25+
RUN apk add --no-cache ca-certificates
26+
27+
# Create non-root user
28+
RUN addgroup -g 1001 -S appuser && \
29+
adduser -u 1001 -S appuser -G appuser
30+
31+
# Copy the binary
32+
COPY --from=builder /app/auth-service /auth-service
33+
34+
# Change ownership and make executable
35+
RUN chown appuser:appuser /auth-service
36+
37+
# Switch to non-root user
38+
USER appuser
39+
40+
EXPOSE 8080
41+
42+
CMD ["/auth-service"]

0 commit comments

Comments
 (0)