From 70e721cc31a1d6c0c76620c19d98d51cd0f81f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Fri, 9 Jan 2026 11:24:17 +0100 Subject: [PATCH] Initial commit: Gitea Actions demo project with Docker build Add simple Node.js Hello World application with automated Docker build and push workflow using Gitea Actions. The workflow builds and pushes images to the Gitea registry with versioning from package.json. Co-Authored-By: Claude Sonnet 4.5 --- .dockerignore | 8 ++++ .gitea/workflows/build.yml | 40 +++++++++++++++++++ Dockerfile | 11 ++++++ README.md | 79 ++++++++++++++++++++++++++++++++++++++ index.js | 1 + package.json | 13 +++++++ 6 files changed, 152 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/build.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..568d829 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +npm-debug.log +.git +.gitignore +.gitea +README.md +.dockerignore +Dockerfile diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..09e61aa --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Read package.json version + id: package-version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Building version: $VERSION" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + registry.budakova.org/knee-cola/gitea-actions-demo-project:${{ steps.package-version.outputs.version }} + registry.budakova.org/knee-cola/gitea-actions-demo-project:latest + cache-from: type=registry,ref=registry.budakova.org/knee-cola/gitea-actions-demo-project:buildcache + cache-to: type=registry,ref=registry.budakova.org/knee-cola/gitea-actions-demo-project:buildcache,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f2b97e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:18-alpine + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install --production + +COPY index.js ./ + +CMD ["node", "index.js"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b185de --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# Gitea Actions Demo Project + +A simple Node.js "Hello World" application demonstrating Gitea Actions CI/CD pipeline with Docker build and push. + +## Project Structure + +``` +. +├── .gitea/ +│ └── workflows/ +│ └── build.yml # Gitea Actions workflow +├── index.js # Main application +├── package.json # Project configuration +├── Dockerfile # Docker image definition +├── .dockerignore # Docker ignore file +└── README.md # This file +``` + +## Application + +The application is a simple Node.js script that prints "Hello World" to the console. + +### Running Locally + +```bash +node index.js +``` + +### Running with Docker + +```bash +# Build the image +docker build -t gitea-actions-demo-project:1.0.0 . + +# Run the container +docker run gitea-actions-demo-project:1.0.0 +``` + +## Gitea Actions CI/CD Pipeline + +The project includes a Gitea Actions workflow that automatically: + +1. Triggers on push to `master` or `main` branches +2. Checks out the code +3. Reads the version from `package.json` +4. Builds a Docker image +5. Pushes the image to `registry.budakova.org/knee-cola/gitea-actions-demo-project:` +6. Also tags and pushes as `latest` + +### Setup Requirements + +To use the Gitea Actions workflow, you need to configure the following secrets in your Gitea repository: + +1. Go to your repository settings +2. Navigate to Secrets section +3. Add the following secrets: + - `DOCKER_USERNAME`: Your Docker registry username + - `DOCKER_PASSWORD`: Your Docker registry password + +### Workflow File + +The workflow is defined in [.gitea/workflows/build.yml](.gitea/workflows/build.yml) + +### Image Naming + +Images are pushed with two tags: +- `registry.budakova.org/knee-cola/gitea-actions-demo-project:` +- `registry.budakova.org/knee-cola/gitea-actions-demo-project:latest` + +## Updating the Version + +To change the version of your Docker image, simply update the `version` field in [package.json](package.json). The next push to master/main will build and push the new version. + +## Testing the Workflow + +1. Make a change to the code or update the version in `package.json` +2. Commit and push to master/main branch +3. Check the Actions tab in your Gitea repository to see the workflow running +4. Once complete, your Docker image will be available at the registry diff --git a/index.js b/index.js new file mode 100644 index 0000000..3451e9b --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +console.log('Hello World'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..8cec26d --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "gitea-actions-demo-project", + "version": "1.0.0", + "description": "Demo project showcasing Gitea Actions with Docker build and push", + "main": "index.js", + "scripts": { + "start": "node index.js", + "test": "echo \"No tests yet\" && exit 0" + }, + "keywords": ["gitea", "actions", "docker", "demo"], + "author": "", + "license": "MIT" +}