Skip to content

Commit

Permalink
docker action
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujstor committed Jun 21, 2024
1 parent 6b7a8c0 commit a2bc2f7
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 130 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker image

on:
push:
branches:
- refactor
- master
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Run docker tag sh and export var from config.yml
run: |
./docker_tag.sh
- name: Export env variabels
uses: cardinalby/export-env-action@v2
with:
envFile: '.env'

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_REPO_NAME }}:${{ env.NEW_TAG }}
if: ${{ env.PUSH_TO_DOCKER }} == 'true'
17 changes: 8 additions & 9 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
name: Linting
name: continuous integration

on:
push:
paths:
- '**.go'
- go.sum
- go.mod
branches-ignore:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-version: '1.22.2'

- name: Deps cache
id: cache-go-deps
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: go-deps-cache
with:
Expand All @@ -33,14 +31,15 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
- if: ${{ steps.cache-go-deps.outputs.cache-hit != 'true' }}
name: List the state of node modules
name: List the state of go modules
continue-on-error: true
run: go mod graph

- name: Install dependencies
run: |
go mod tidy
go mod download
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
run: golangci-lint run
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN go install github.com/a-h/templ/cmd/templ@latest
RUN templ generate
RUN go build -o main cmd/api/main.go

FROM alpine:3.20.1 as prod
FROM alpine:3.20.1
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE 5000
Expand Down
104 changes: 0 additions & 104 deletions Jenkinsfile

This file was deleted.

7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

This static website is built with Go and Templ.


## Jenkins Pipeline
The pipeline is designed to automate the processes of testing, building, and deploying a web application using Docker.
It creates an image and pushes it to DockerHub.

![](https://i.imgur.com/llEoE4e.png)

## Deployment
Deployment can be achieved through self-hosting service provided by [Collify](https://coolify.io/docs/installation).

Expand Down
5 changes: 5 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker:
DOCKER_HUB_USERNAME: ujstor
DOCKER_REPO_NAME: portfolio-web-go
VERSION_PART: Patch # Patch, Minor, major
PUSH_TO_DOCKER: true
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
version: '3.8'

services:
web:
build:
context: .
dockerfile: Dockerfile
target: prod
ports:
- 5000:5000
19 changes: 13 additions & 6 deletions docker_tag.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/bin/bash

DOCKER_HUB_USERNAME=$1
DOCKER_REPO_NAME=$2
VERSION_PART=$3
eval $(yq e '.docker | to_entries | .[] | "export \(.key)=\(.value)"' config.yml)

DOCKER_IMAGE="$DOCKER_HUB_USERNAME/$DOCKER_REPO_NAME"

TAGS=$(curl -s "https://hub.docker.com/v2/repositories/$DOCKER_IMAGE/tags/?page_size=100" | jq -r '.results[].name')

if [ -z "$TAGS" ]; then
DEFAULT_TAG="1.0.0"
DEFAULT_TAG="0.0.1"
NEW_TAG="$DEFAULT_TAG"
else
LATEST_TAG=$(echo "$TAGS" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)

if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="1.0.0"
LATEST_TAG="0.0.1"
fi

IFS='.' read -ra PARTS <<< "$LATEST_TAG"
Expand All @@ -35,4 +33,13 @@ else
fi
fi

echo $NEW_TAG
create_env_file() {
cat << EOF > .env
DOCKER_HUB_USERNAME=$DOCKER_HUB_USERNAME
DOCKER_REPO_NAME=$DOCKER_REPO_NAME
NEW_TAG=$NEW_TAG
PUSH_TO_DOCKER=$PUSH_TO_DOCKER
EOF
}

create_env_file

0 comments on commit a2bc2f7

Please sign in to comment.