refactor: reduce docker image size
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
.git
|
||||
/bin/
|
||||
/.shards/
|
||||
/bruno/
|
||||
/spec/
|
||||
/sqlite/
|
||||
|
||||
@@ -39,6 +39,15 @@ jobs:
|
||||
VERSION=$(echo $VERSION | tr -d '\n\r')
|
||||
echo "RELEASE_TAG=$VERSION" >> $GITHUB_ENV
|
||||
|
||||
- name: Set tags
|
||||
id: set_tags
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "release" ]]; then
|
||||
echo "TAGS=latest,${{ env.RELEASE_TAG }}" >> $GITHUB_ENV
|
||||
else
|
||||
echo "TAGS=latest" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Build and push image
|
||||
id: push
|
||||
uses: docker/build-push-action@v5.0.0
|
||||
@@ -46,9 +55,7 @@ jobs:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: |
|
||||
sjdonado/bit:latest
|
||||
${{ github.event_name == 'release' && env.RELEASE_TAG && 'sjdonado/bit:${{ env.RELEASE_TAG }}' || '' }}
|
||||
tags: sjdonado/bit:${{ env.TAGS }}
|
||||
|
||||
- name: Attest
|
||||
uses: actions/attest-build-provenance@v1
|
||||
|
||||
+19
-9
@@ -1,5 +1,6 @@
|
||||
FROM alpine:edge as base
|
||||
FROM alpine:edge AS build
|
||||
|
||||
ENV ENV=production
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN apk update && apk add --no-cache \
|
||||
@@ -9,20 +10,29 @@ RUN apk update && apk add --no-cache \
|
||||
sqlite-dev \
|
||||
openssl-dev
|
||||
|
||||
FROM base AS build
|
||||
ENV ENV=production
|
||||
|
||||
COPY . .
|
||||
COPY . .
|
||||
|
||||
RUN shards install
|
||||
RUN shards build --progress
|
||||
RUN shards build --release --no-debug
|
||||
|
||||
FROM alpine:edge AS runtime
|
||||
|
||||
ENV ENV=production
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN apk add --no-cache \
|
||||
gc \
|
||||
pcre2 \
|
||||
libevent \
|
||||
yaml \
|
||||
sqlite-libs \
|
||||
openssl
|
||||
|
||||
RUN mkdir -p sqlite
|
||||
|
||||
FROM base AS release
|
||||
RUN mkdir -p /usr/src/app/sqlite
|
||||
COPY --from=build /usr/src/app/db db
|
||||
COPY --from=build /usr/src/app/data data
|
||||
COPY --from=build /usr/src/app/bin /usr/local/bin
|
||||
COPY --from=build /usr/src/app/data /usr/local/data
|
||||
|
||||
EXPOSE 4000/tcp
|
||||
CMD ["bit"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[](https://hub.docker.com/repository/docker/sjdonado/bit/general)
|
||||
[](https://hub.docker.com/repository/docker/sjdonado/bit/general)
|
||||
[](https://hub.docker.com/repository/docker/sjdonado/bit/general)
|
||||
[](https://hub.docker.com/repository/docker/sjdonado/bit)
|
||||
[](https://hub.docker.com/repository/docker/sjdonado/bit)
|
||||
[](https://hub.docker.com/repository/docker/sjdonado/bit)
|
||||
|
||||
# Benchmark
|
||||
|
||||
@@ -39,7 +39,7 @@ Average Response Time: 12.37 µs
|
||||
|
||||
# Self-hosted
|
||||
|
||||
- Run via docker-compose
|
||||
## Run via docker-compose
|
||||
|
||||
```bash
|
||||
docker-compose up
|
||||
@@ -48,7 +48,7 @@ docker-compose exec -it app migrate
|
||||
docker-compose exec -it app cli --create-user=Admin
|
||||
```
|
||||
|
||||
- Run via docker cli
|
||||
## Run via docker cli
|
||||
|
||||
```bash
|
||||
docker run \
|
||||
@@ -63,7 +63,7 @@ docker exec -it bit migrate
|
||||
docker exec -it bit cli --create-user=Admin
|
||||
```
|
||||
|
||||
- Dokku
|
||||
## Dokku
|
||||
|
||||
```dockerfile
|
||||
FROM sjdonado/bit
|
||||
@@ -93,11 +93,9 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
1. **Ping the API**
|
||||
|
||||
- **Endpoint**: `/api/ping`
|
||||
- **HTTP Method**: GET
|
||||
- **Description**: Ping the API to check if it's running
|
||||
- **Payload**: -
|
||||
- **Response Example**:
|
||||
- Endpoint: `GET /api/ping`
|
||||
- Payload: None
|
||||
- Response Example
|
||||
```json
|
||||
{
|
||||
"message": "pong"
|
||||
@@ -106,12 +104,10 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
2. **Retrieve a link by its slug**
|
||||
|
||||
- **Endpoint**: `/:slug`
|
||||
- **HTTP Method**: GET
|
||||
- **Description**: Retrieve a link by its slug
|
||||
- **Payload**: -
|
||||
- **Headers**: `X-Api-Key`
|
||||
- **Response Example**:
|
||||
- Endpoint: `GET /:slug`
|
||||
- Headers: `X-Api-Key`
|
||||
- Payload: None
|
||||
- Response Example
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
@@ -135,12 +131,10 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
3. **Retrieve all links**
|
||||
|
||||
- **Endpoint**: `/api/links`
|
||||
- **HTTP Method**: GET
|
||||
- **Description**: Retrieve all links
|
||||
- **Payload**: -
|
||||
- **Headers**: `X-Api-Key`
|
||||
- **Response Example**:
|
||||
- Endpoint: `GET /api/links`
|
||||
- Headers: `X-Api-Key`
|
||||
- Payload: None
|
||||
- Response Example
|
||||
```json
|
||||
{
|
||||
"data": [
|
||||
@@ -166,12 +160,10 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
4. **Retrieve a link by its ID**
|
||||
|
||||
- **Endpoint**: `/api/links/:id`
|
||||
- **HTTP Method**: GET
|
||||
- **Description**: Retrieve a link by its ID
|
||||
- **Payload**: -
|
||||
- **Headers**: `X-Api-Key`
|
||||
- **Response Example**:
|
||||
- Endpoint: `GET /api/links/:id`
|
||||
- Headers: `X-Api-Key`
|
||||
- Payload: None
|
||||
- Response Example
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
@@ -195,17 +187,15 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
5. **Create a new link**
|
||||
|
||||
- **Endpoint**: `/api/links`
|
||||
- **HTTP Method**: POST
|
||||
- **Description**: Create a new link
|
||||
- **Payload**:
|
||||
- Endpoint\*\*: `POST /api/links`
|
||||
- Payload:
|
||||
```json
|
||||
{
|
||||
"url": "https://example.com"
|
||||
}
|
||||
```
|
||||
- **Headers**: `X-Api-Key`
|
||||
- **Response Example**:
|
||||
- Headers: `X-Api-Key`
|
||||
- Response Example:
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
@@ -219,17 +209,15 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
6. **Update an existing link by its ID**
|
||||
|
||||
- **Endpoint**: `/api/links/:id`
|
||||
- **HTTP Method**: PUT
|
||||
- **Description**: Update an existing link by its ID
|
||||
- **Payload**:
|
||||
- Endpoint: `PUT /api/links/:id`
|
||||
- Payload:
|
||||
```json
|
||||
{
|
||||
"url": "https://newexample.com"
|
||||
}
|
||||
```
|
||||
- **Headers**: `X-Api-Key`
|
||||
- **Response Example**:
|
||||
- Headers: `X-Api-Key`
|
||||
- Response Example:
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
@@ -243,12 +231,10 @@ dokku run bit cli --create-user=Admin
|
||||
|
||||
7. **Delete a link by its ID**
|
||||
|
||||
- **Endpoint**: `/api/links/:id`
|
||||
- **HTTP Method**: DELETE
|
||||
- **Description**: Delete a link by its ID
|
||||
- **Payload**: -
|
||||
- **Headers**: `X-Api-Key`
|
||||
- **Response Example**:
|
||||
- Endpoint: `DELETE /api/links/:id`
|
||||
- Payload: None
|
||||
- Headers: `X-Api-Key`
|
||||
- Response Example:
|
||||
```json
|
||||
{
|
||||
"message": "Link deleted"
|
||||
@@ -267,7 +253,7 @@ Options:
|
||||
|
||||
# Development
|
||||
|
||||
1. **Installation**
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
brew tap amberframework/micrate
|
||||
@@ -279,19 +265,19 @@ shards run migrate
|
||||
shards run bit
|
||||
```
|
||||
|
||||
2. **Generate the `X-Api-Key`**
|
||||
## Generate the `X-Api-Key`
|
||||
|
||||
```bash
|
||||
shards run cli -- --create-user=Admin
|
||||
```
|
||||
|
||||
# Run tests
|
||||
## Run tests
|
||||
|
||||
```bash
|
||||
ENV=test crystal spec
|
||||
```
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
1. Fork it (<https://github.com/sjdonado/bit/fork>)
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
|
||||
Reference in New Issue
Block a user