Skip to content

Commit

Permalink
feat: remove .env.build and automate env setup via make setup
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-stark-eth committed Sep 15, 2024
1 parent 8aa287c commit 3398584
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 52 deletions.
16 changes: 0 additions & 16 deletions .env.build

This file was deleted.

33 changes: 12 additions & 21 deletions .github/actions/docker-prepare-workspace/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ inputs:
required: false
default: 'latest'
description: 'Value to export as DOCKER_IMAGE_TAG'
make-init-targets:
make-init-targets-before:
required: true
description: 'Make targets to execute to finish initialization'
description: 'Make targets to execute before docker container start'
make-init-targets-after:
required: true
description: 'Make targets to execute after docker container start'
github_token:
description: 'GitHub token to authenticate API requests.'
required: true
Expand All @@ -36,23 +39,6 @@ runs:
username: ${{ github.actor }}
password: ${{ inputs.github_token }}

- name: Concatenate Dotenv File
shell: bash
run: cat .env.build >> .env

- name: Dump UID & GID
id: docker-workspace-user
shell: bash
run: |
echo "uid=$(id -u)" >> $GITHUB_OUTPUT
echo "gid=$(id -g)" >> $GITHUB_OUTPUT
- name: Change env uid and gid
shell: bash
run: |
echo "UID=${{ steps.docker-workspace-user.outputs.uid }}" >> .env
echo "GID=${{ steps.docker-workspace-user.outputs.gid }}" >> .env
- name: Determine Docker Compose Services to Start
id: compose-services
shell: bash
Expand All @@ -72,15 +58,20 @@ runs:
services=$(echo "${services[@]}" | tr -s ' ' | xargs | sort)
echo "services=$services" >> $GITHUB_OUTPUT
- name: Run Make Initialization Targets
if: inputs.make-init-targets-before != ''
shell: bash
run: make ${{ inputs.make-init-targets-before }}

- name: Start Docker Compose Services
shell: bash
run: |
docker compose up -d --no-build --no-deps --quiet-pull --wait ${{ steps.compose-services.outputs.services }}
- name: Run Make Initialization Targets
if: inputs.make-init-targets != ''
if: inputs.make-init-targets-after != ''
shell: bash
run: make ${{ inputs.make-init-targets }}
run: make ${{ inputs.make-init-targets-after }}

- name: Output Used Docker Images
if: ${{ success() }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ jobs:
with:
docker-image-tag: ${{ needs.docker-bake.outputs.docker-image-tag }}
docker-compose-services: 'app'
make-init-targets: 'install'
make-init-targets-before: 'setup'
make-init-targets-after: 'install'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run Svelte Check
Expand All @@ -82,7 +83,8 @@ jobs:
uses: ./.github/actions/docker-prepare-workspace
with:
docker-image-tag: ${{ needs.docker-bake.outputs.docker-image-tag }}
make-init-targets: 'install'
make-init-targets-before: 'setup'
make-init-targets-after: 'install'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run Test Suite
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/docker-bake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,10 @@ jobs:
driver-opts: network=host

- name: Copy Dist Dotenv File
run: cp .env.build .env
run: cp .env.dist .env

- name: Dump UID & GID
id: docker-workspace-user
shell: bash
run: |
echo "uid=$(id -u)" >> $GITHUB_OUTPUT
echo "gid=$(id -g)" >> $GITHUB_OUTPUT
- name: Change env uid and gid
shell: bash
run: |
echo "UID=${{ steps.docker-workspace-user.outputs.uid }}" >> .env
echo "GID=${{ steps.docker-workspace-user.outputs.gid }}" >> .env
- name: Run setup.sh
run: ./setup.sh

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ build:
ps:
@echo "Listing running containers..."
docker compose -f $(DOCKER_COMPOSE_FILE) ps

setup:
@echo "Running setup script..."
sh setup.sh
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ This template offers the following things, ready to use, in a dockerized environ
npx degit bavragor/vite-svelte-docker-template app-name
```

## Requirements

- Docker
- make

## Installation

```sh
make setup
make up
make install
```
Expand Down
20 changes: 20 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Check if .env.dist file exists
if [ ! -f .env.dist ]; then
echo ".env.dist file not found!"
exit 1
fi

# Copy .env.dist to .env
cp .env.dist .env

# Get the current user's UID and GID
USER_UID=$(id -u)
USER_GID=$(id -g)

# Replace placeholders in .env with actual UID and GID
sed -i "s/UID=.*$/UID=${USER_UID}/" .env
sed -i "s/GID=.*$/GID=${USER_GID}/" .env

echo ".env file has been created and updated with UID and GID."

0 comments on commit 3398584

Please sign in to comment.