Skip to content

Commit

Permalink
docker prod dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujstor committed Jan 26, 2024
1 parent f974f34 commit 2f980cf
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 34 deletions.
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
FROM golang:1.21-alpine
FROM golang:1.20-alpine as base

RUN apk add --no-cache make

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

FROM base as dev
RUN make build
EXPOSE ${PORT}
CMD [ "sh", "-c", "echo 'y' | make watch" ]

FROM base as build
RUN go build -o main cmd/api/main.go

FROM alpine:3.19.0 as prod
WORKDIR /app
COPY --from=build /app/main /app/main
COPY cmd/web cmd/web
EXPOSE ${PORT}

CMD ["./main"]
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pipeline {
}
steps {
script {
sh "docker build --no-cache -t ${DOCKER_HUB_USERNAME}/${DOCKER_REPO_NAME}:${TAG} ."
sh "docker build --no-cache -t ${DOCKER_HUB_USERNAME}/${DOCKER_REPO_NAME}:${TAG} --target prod ."
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ watch:
fi; \
fi

.PHONY: all build run test clean
.PHONY: all build docker-build run docker-run push test clea watch
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ The website is containerized using Docker Compose for easy deployment and scalin

## Docker Compose

Pull image from DockerHub and start the Docker containers using Docker Compose:
Build image and start the Docker containers using Docker Compose:

```bash
docker compose up -d
docker compose up web-prod --build -d
```

This command will build the Docker image for your website and start the container.
Expand Down
Binary file added cmd/web/static/img/jpg/coolify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/web/static/img/webp/coolify.webp
Binary file not shown.
90 changes: 68 additions & 22 deletions cmd/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ <h1>Languages & Tools</h1>
width="70"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/kubernetes/kubernetes-plain.svg"
/>
<img
height="70"
width="70"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/terraform/terraform-original.svg"
/>
<img
height="70"
width="70"
Expand All @@ -108,7 +113,7 @@ <h1>Languages & Tools</h1>
width="70"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/linux/linux-original.svg"
/>
<img
<img
height="70"
width="70"
src="./static/svg/aws.svg"
Expand Down Expand Up @@ -205,50 +210,46 @@ <h3>Self-Hosting AI Models</h3>
</div>
</div>

<!-- User Project #3: Probit API -->
<!-- User Project #3: Self hosted Coolify -->
<div class="user-projects">
<div class="images-right">
<picture>
<source type="image/webp"
srcset="./static/img/webp/probit.webp"
srcset="./static/img/webp/coolify.webp"
sizes="(max-width: 600px) 480px, 800px" />
<img src="./static/img/jpg/probit.jpg"
alt="ProBit Global API"
<img src="./static/img/jpg/coolify.jpg"
alt="Coolify instance on Hetzner"
style="width:auto;max-width:100%;" />
</picture>
</div>
<div class="contents" style="text-align: center">
<h3>ProBit Global API</h3>
<h3>Coolify instance on Hetzner</h3>
<div>
<img
height="62"
width="62"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/flask/flask-original.svg"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/terraform/terraform-original.svg"
/>
&nbsp;
<img
height="62"
width="62"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/html5/html5-original.svg"
height="115"
width="115"
src="./static/svg/hetzner.svg"
/>
&nbsp;
<img
height="62"
width="62"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/bootstrap/bootstrap-plain.svg"
/>
</div>
<p style="text-align: justify">
Effortlessly integrate with the ProBit Global Exchange API using this repository.
It simplifies the setup with Docker and automates deployment through a Jenkins pipeline.
Essential for effective order monitoring, the setup involves easy credential configuration
and supports automated updates linked to GitHub changes.
Deploy Coolify on Hetzner Cloud using the Terraform. This project aims to create a highly optimized,
auto-upgradable, highly available and cost-effective self hosted Coolify instance for deployng your
projects on Hetzner Cloud. Coolify is an all-in one PaaS that helps you to self-host your own applications,
databases or services without managing your servers, also known as an open-source & self-hostable
Heroku / Netlify / Vercel alternative.
</p>
<a class="project-link" target="_blank" href="https://probit.astipan.com/">Check it out!</a>
<a class="project-link" target="_blank" href="https://coolify.io/docs/">Check it out!</a>
&nbsp;
<a class="project-link" target="_blank" href="https://github.com/Ujstor/probit-exchange-api">GitHub</a>
<a class="project-link" target="_blank" href="https://github.com/Ujstor/coolify-hetzner-terraform">GitHub</a>
</div>
</di>
</div>

<!-- User Project #4: fast API -->
<div class="user-projects">
Expand Down Expand Up @@ -301,6 +302,51 @@ <h3>Social Media FastAPI</h3>
&nbsp;
<a class="project-link" target="_blank" href="https://www.postman.com/ujstor/workspace/fastapi-test/">Postman</a>
</div>
</div>

<!-- User Project #5: Probit API -->
<div class="user-projects">
<div class="images-right">
<picture>
<source type="image/webp"
srcset="./static/img/webp/probit.webp"
sizes="(max-width: 600px) 480px, 800px" />
<img src="./static/img/jpg/probit.jpg"
alt="ProBit Global API"
style="width:auto;max-width:100%;" />
</picture>
</div>
<div class="contents" style="text-align: center">
<h3>ProBit Global API</h3>
<div>
<img
height="62"
width="62"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/flask/flask-original.svg"
/>
&nbsp;
<img
height="62"
width="62"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/html5/html5-original.svg"
/>
&nbsp;
<img
height="62"
width="62"
src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/bootstrap/bootstrap-plain.svg"
/>
</div>
<p style="text-align: justify">
Effortlessly integrate with the ProBit Global Exchange API using this repository.
It simplifies the setup with Docker and automates deployment through a Jenkins pipeline.
Essential for effective order monitoring, the setup involves easy credential configuration
and supports automated updates linked to GitHub changes.
</p>
<a class="project-link" target="_blank" href="https://probit.astipan.com/">Check it out!</a>
&nbsp;
<a class="project-link" target="_blank" href="https://github.com/Ujstor/probit-exchange-api">GitHub</a>
</div>
</div>
</section>

Expand Down
6 changes: 4 additions & 2 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: '3.8'

services:
web:
image: ujstor/portfolio-web-go:1.0.7
image: ujstor/portfolio-web-go:1.0.8
ports:
- ${PORT}:${PORT}
- ${PORT}:${PORT}
environment:
- PORT=${PORT}
27 changes: 24 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
version: '3.8'

services:
web:
build: .
web-dev:
build:
context: .
dockerfile: Dockerfile
target: dev
ports:
- ${PORT}:${PORT}
- ${PORT}:${PORT}
environment:
- PORT=${PORT}
volumes:
- ./:/app

web-prod:
build:
context: .
dockerfile: Dockerfile
target: prod
ports:
- ${PORT}:${PORT}
environment:
- PORT=${PORT}

# docker-compose up --scale web-dev=0 --scale web-prod=1 --build
# docker-compose up web-prod --build
# docker-compose up web-dev --build

0 comments on commit 2f980cf

Please sign in to comment.