Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions .github/workflows/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Container

on:
push:
branches:
- "develop"
- "main"
- "releases/**/*"
pull_request:
branches:
- "develop"
- "main"

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test (Docker)
runs-on: ubuntu-latest

strategy:
matrix:
target: [debug, release]

steps:
- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v3

- id: build
name: Build
uses: docker/build-push-action@v5
with:
file: ./Containerfile
push: false
load: true
target: ${{ matrix.target }}
tags: torrust-index-gui:local
cache-from: type=gha
cache-to: type=gha

- id: inspect
name: Inspect
run: docker image inspect torrust-index-gui:local

- id: checkout
name: Checkout Repository
uses: actions/checkout@v4

- id: compose
name: Compose
run: docker compose build

context:
name: Context
needs: test
runs-on: ubuntu-latest

outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
version: ${{ steps.check.outputs.version }}

steps:
- id: check
name: Check Context
run: |
if [[ "${{ github.repository }}" == "torrust/torrust-index-gui" ]]; then
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then

echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
echo "On \`main\` Branch, Type: \`development\`"

elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then

echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
echo "On \`develop\` Branch, Type: \`development\`"

elif [[ $(echo "${{ github.ref }}" | grep -P '^(refs\/heads\/releases\/)(v)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$') ]]; then

version=$(echo "${{ github.ref }}" | sed -n -E 's/^(refs\/heads\/releases\/)//p')
echo "version=$version" >> $GITHUB_OUTPUT
echo "type=release" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
echo "In \`releases/$version\` Branch, Type: \`release\`"

else
echo "Not Correct Branch. Will Not Continue"
fi
else
echo "Not a Push Event. Will Not Continue"
fi
else
echo "On a Forked Repository. Will Not Continue"
fi

publish_development:
name: Publish (Development)
environment: dockerhub-torrust
needs: context
if: needs.context.outputs.continue == 'true' && needs.context.outputs.type == 'development'
runs-on: ubuntu-latest

steps:
- id: meta
name: Docker Meta
uses: docker/metadata-action@v5
with:
images: |
"${{ vars.DOCKER_HUB_USERNAME }}/${{vars.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=ref,event=branch

- id: login
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./Containerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha

publish_release:
name: Publish (Release)
environment: dockerhub-torrust
needs: context
if: needs.context.outputs.continue == 'true' && needs.context.outputs.type == 'release'
runs-on: ubuntu-latest

steps:
- id: meta
name: Docker Meta
uses: docker/metadata-action@v5
with:
images: |
"${{ vars.DOCKER_HUB_USERNAME }}/${{vars.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=semver,value=${{ needs.context.outputs.version }},pattern={{raw}}
type=semver,value=${{ needs.context.outputs.version }},pattern={{version}}
type=semver,value=${{ needs.context.outputs.version }},pattern=v{{major}}
type=semver,value=${{ needs.context.outputs.version }},pattern={{major}}.{{minor}}

- id: login
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./Containerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha
64 changes: 0 additions & 64 deletions .github/workflows/publish_docker_image.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/test_docker_build.yml

This file was deleted.

7 changes: 7 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ VOLUME ["/var/log/torrust/index-gui"]
ENV RUNTIME="runtime"
ENTRYPOINT ["/usr/local/bin/entry.sh"]

## Torrust-Index-GUI (debug)
FROM runtime as debug
ENV RUNTIME="debug"
COPY --from=test /app/.output /app/.output
RUN env
CMD ["sh"]


## Torrust-Index-GUI (release) (default)
FROM runtime as release
Expand Down
1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
tty: true
environment:
- USER_ID=${USER_ID}
- NUXT_PUBLIC_API_BASE=${TORRUST_INDEX_GUI_API_BASE_URL:-http://localhost:3001/v1}
ports:
- 3000:3000
- 24678:24678
Expand Down
16 changes: 16 additions & 0 deletions contrib/dev-tools/container/docker-build-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

echo "Building docker image ..."

USER_ID=${USER_ID:-1001}
TORRUST_INDEX_GUI_API_BASE_URL=${TORRUST_INDEX_GUI_API_BASE_URL:-http://localhost:3001/v1}

echo "USER_ID: $USER_ID"
echo "TORRUST_INDEX_GUI_API_BASE_URL: $TORRUST_INDEX_GUI_API_BASE_URL"

docker build \
--build-arg USER_ID="$USER_ID" \
--build-arg API_BASE_URL="$TORRUST_INDEX_GUI_API_BASE_URL" \
--target debug \
--tag torrust-index-gui:debug \
--file Containerfile .
1 change: 1 addition & 0 deletions contrib/dev-tools/container/docker-run-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ mkdir -p ./storage/index-gui/lib/ ./storage/index-gui/log/ ./storage/index-gui/e

docker run -it \
--env USER_ID="$(id -u)" \
--env NUXT_PUBLIC_API_BASE="http://localhost:3001/v1" \
--publish 3000:3000/tcp \
torrust-index-gui:release
1 change: 1 addition & 0 deletions contrib/dev-tools/container/docker-run-public.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ mkdir -p ./storage/index-gui/log/

docker run -it \
--env USER_ID="$(id -u)" \
--env NUXT_PUBLIC_API_BASE="http://localhost:3001/v1" \
--publish 3000:3000/tcp \
torrust/index-gui:latest