Skip to content

Commit ac77f14

Browse files
authored
feat: add Dockerfile and build workflow (#23)
1 parent e013d2a commit ac77f14

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build and release
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
branches:
9+
- "main"
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
build-and-push-image:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v2
25+
26+
- name: Log in to the Container registry
27+
uses: docker/[email protected]
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract metadata (tags, labels) for Docker
34+
id: meta
35+
uses: docker/[email protected]
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
39+
- name: Build and push Docker image
40+
uses: docker/[email protected]
41+
with:
42+
context: .
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax=docker/dockerfile:1
2+
FROM golang:1.18-alpine as builder
3+
4+
# needed for github.com/mattn/go-sqlite3
5+
RUN apk add --no-cache gcc g++
6+
7+
WORKDIR /app
8+
COPY go.mod go.sum ./
9+
RUN go mod download
10+
11+
COPY internal ./internal
12+
COPY main.go ./
13+
RUN go build -o /backend
14+
15+
# Build final image
16+
FROM alpine:3.15.1
17+
WORKDIR /app
18+
COPY --from=builder /backend /app/backend
19+
ENTRYPOINT ["/app/backend"]

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ require (
3737
google.golang.org/protobuf v1.27.1 // indirect
3838
gopkg.in/yaml.v2 v2.4.0 // indirect
3939
)
40+
41+
replace github.com/envelope-zero/backend/internal/routing => ./internal/routing

0 commit comments

Comments
 (0)