-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ci pipeline with docker build
- Loading branch information
Showing
4 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Create and publish a Docker image | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
tags: | ||
- "*" | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: docker/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
run: gen | ||
BINARY_NAME := skatcounter | ||
IMAGE_NAME := ghcr.io/tarow/$(BINARY_NAME) | ||
TAGS := latest | ||
|
||
|
||
all: clean install gen tidy build | ||
|
||
run: | ||
go run main.go | ||
|
||
dev: | ||
air | ||
|
||
build: | ||
go build -o bin/$(BINARY_NAME) main.go | ||
|
||
clean: | ||
rm -f bin/* | ||
|
||
install: | ||
go mod download | ||
|
||
lint: | ||
@golangci-lint --version | ||
golangci-lint run | ||
|
||
tidy: | ||
go mod tidy | ||
|
||
gen: | ||
templ generate | ||
|
||
dev: gen | ||
air | ||
docker-build: | ||
docker build -f docker/Dockerfile . --tag $(IMAGE_NAME):$(firstword $(TAGS)) | ||
$(foreach tag,$(filter-out $(firstword $(TAGS)),$(TAGS)),\ | ||
docker tag $(IMAGE_NAME):$(firstword $(TAGS)) $(IMAGE_NAME):$(tag); \ | ||
) | ||
|
||
docker-push: | ||
$(foreach tag, $(TAGS),\ | ||
docker push $(IMAGE_NAME):$(tag); \ | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM golang:1.21.5-alpine as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
|
||
COPY main.go . | ||
COPY internal/ internal/ | ||
COPY static/ static/ | ||
COPY templates/ templates/ | ||
|
||
RUN go build -o skatcounter | ||
|
||
FROM alpine:3.18 | ||
|
||
WORKDIR /app | ||
COPY --from=builder /app/skatcounter /usr/bin/skatcounter | ||
|
||
CMD ["skatcounter"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters