Skip to content

Commit 3ffdd60

Browse files
main: api dockerfile, makefile and docker-compose (stellar#22)
What Adds the Dockerfile for building the API's Docker image. A Makefile is also added to make the CI/CD later easier. The docker-compose is also changed to use the new Dockerfile and run the API more easily. Why Building the system's Docker image.
1 parent ef6aeda commit 3ffdd60

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# To build:
2+
# make docker-build
3+
# To push:
4+
# make docker-push
5+
6+
FROM golang:1.22.4-bullseye as build
7+
ARG GIT_COMMIT
8+
9+
WORKDIR /src/wallet-backend
10+
ADD go.mod go.sum ./
11+
RUN go mod download
12+
ADD . ./
13+
RUN go build -o /bin/wallet-backend -ldflags "-X main.GitCommit=$GIT_COMMIT" .
14+
15+
16+
FROM ubuntu:22.04
17+
18+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
19+
COPY --from=build /bin/wallet-backend /app/
20+
EXPOSE 8001
21+
WORKDIR /app
22+
ENTRYPOINT ["./wallet-backend"]

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Check if we need to prepend docker command with sudo
2+
SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")
3+
4+
LABEL ?= $(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty-$(shell id -u -n))
5+
# If TAG is not provided set default value
6+
TAG ?= stellar/wallet-backend:$(LABEL)
7+
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
8+
BUILD_DATE := $(shell date -u +%FT%TZ)
9+
10+
docker-build:
11+
$(SUDO) docker build -f Dockerfile --pull --label org.opencontainers.image.created="$(BUILD_DATE)" -t $(TAG) --build-arg GIT_COMMIT=$(LABEL) .
12+
13+
docker-push:
14+
$(SUDO) docker push $(TAG)
15+
16+
go-install:
17+
go install -ldflags "-X main.GitCommit=$(LABEL)" .

cmd/serve.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ func (c *serveCmd) Command() *cobra.Command {
2424
Usage: "Port to listen and serve on",
2525
OptType: types.Int,
2626
ConfigKey: &cfg.Port,
27-
FlagDefault: 8000,
27+
FlagDefault: 8001,
2828
Required: false,
2929
},
3030
{
3131
Name: "server-base-url",
3232
Usage: "The server base URL",
3333
OptType: types.String,
3434
ConfigKey: &cfg.ServerBaseURL,
35-
FlagDefault: "http://localhost:8000",
35+
FlagDefault: "http://localhost:8001",
3636
Required: true,
3737
},
3838
{

docker-compose.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
db:
43
image: postgres:12-alpine
@@ -9,6 +8,27 @@ services:
98
- postgres-db:/var/lib/postgresql/data
109
ports:
1110
- 5432:5432
11+
api:
12+
image: stellar/wallet-backend:development
13+
build: ./
14+
depends_on:
15+
db:
16+
condition: service_started
17+
ports:
18+
- 8001:8001
19+
entrypoint: ""
20+
command:
21+
- sh
22+
- -c
23+
- |
24+
./wallet-backend migrate up
25+
./wallet-backend serve
26+
environment:
27+
DATABASE_URL: postgres://postgres@db:5432/wallet-backend?sslmode=disable
28+
PORT: 8001
29+
SERVER_BASE_URL: http://localhost:8001
30+
LOG_LEVEL: TRACE
31+
WALLET_SIGNING_KEY: GAXBXPBZNJG6PQBE7M3VTEZ4EIRVDL4TSTQEVHEOYOLMYQZWJ4WUA4YF
1232

1333
volumes:
1434
postgres-db:

main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package main
22

3-
import "github.com/stellar/wallet-backend/cmd"
3+
import (
4+
"github.com/stellar/wallet-backend/cmd"
5+
)
6+
7+
// GitCommit is populated at build time by
8+
// go build -ldflags "-X main.GitCommit=$GIT_COMMIT"
9+
var GitCommit string
410

511
func main() {
612
cmd.Execute()

0 commit comments

Comments
 (0)