Skip to content

Commit

Permalink
feat: add base CI
Browse files Browse the repository at this point in the history
  • Loading branch information
logan-bobo committed Jun 19, 2024
1 parent 0e2a126 commit 7928949
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.22.3'
cache: true
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/[email protected]
with:
version: latest
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ FROM alpine:3.20.0 AS base

RUN apk update
RUN apk upgrade
RUN apk add --update go=1.22.3-r0

FROM base AS tester

WORKDIR /opt/url-short

ADD . /opt/url-short

CMD ["go", "test"]

FROM base AS builder

RUN apk add --update go=1.22.3-r0

WORKDIR /build

ADD . /build

RUN go build -o main .

FROM builder AS production
FROM base AS tester

RUN apk add --update go=1.22.3-r0

RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.1

WORKDIR /opt/url-short/

FROM base AS production

WORKDIR /opt/url-short/

Expand Down
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
COMPOSE_TEST_FILE="${PWD}/docker-compose-test.yaml"

fmt:
go fmt ./...
COMPOSE_FILE=${COMPOSE_TEST_FILE} docker compose run --rm --remove-orphans api go fmt
.PHONY:fmt

lint: fmt
golangci-lint run -v
COMPOSE_FILE=${COMPOSE_TEST_FILE} docker compose run --rm --remove-orphans api golangci-lint run -v
.PHONY:lint

vet: lint
go vet ./...
.PHONY:vet

build:
docker build . -t "url-short:latest"
docker build . -t "url-short:latest"
.PHONY:build

build/test:
docker build . -t "url-short:test" --target tester
.PHONY:build/test

run:
docker compose up -d
docker compose up -d
.PHONY:run

stop:
docker compose down
docker compose down
.PHONY:stop

test:
docker build . -t "url-short:test" --target tester
docker run -t "url-short:test"
COMPOSE_FILE=${COMPOSE_TEST_FILE} docker compose run --rm --remove-orphans api go test ./...
.PHONY:test

migrate:
goose -dir sql/schema postgres "postgres://url_short:password@localhost:5002/url_short" up
goose -dir sql/schema postgres "postgres://url_short:password@localhost:5002/url_short" up
.PHONY:migrate
10 changes: 10 additions & 0 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.1'

services:
api:
image: url-short:test
env_file:
- .env
volumes:
- ./:/opt/url-short

0 comments on commit 7928949

Please sign in to comment.