diff --git a/.github/workflows/context.yml b/.github/workflows/context.yml new file mode 100644 index 000000000..2c3966b71 --- /dev/null +++ b/.github/workflows/context.yml @@ -0,0 +1,18 @@ +name: Context Examples + +on: + push: + branches: [ main ] + +jobs: + context-job: + runs-on: ubuntu-latest + steps: + - name: "My Step" + run: | + echo "Action! $MY_ACTION" + echo "Actor! $MY_ACTOR" + env: + MY_ACTION: ${{ github.action }} + MY_ACTOR: ${{ github.actor }} + \ No newline at end of file diff --git a/.github/workflows/custom-action.yml b/.github/workflows/custom-action.yml deleted file mode 100644 index 7a87b53f1..000000000 --- a/.github/workflows/custom-action.yml +++ /dev/null @@ -1,15 +0,0 @@ -on: [push] - -jobs: - my-job: - runs-on: ubuntu-latest - name: A job to say hello - steps: - - name: Hello world action step - id: hello - uses: omenking/barsoom@0.0.6 - with: - name: 'Brown' - # Use the output from the `hello` step - - name: Get the Output - run: echo "The time was ${{ steps.hello.outputs.greeting }}" \ No newline at end of file diff --git a/.github/workflows/jobs.yml b/.github/workflows/jobs.yml new file mode 100644 index 000000000..c3b0e8ca1 --- /dev/null +++ b/.github/workflows/jobs.yml @@ -0,0 +1,20 @@ +name: "Dependent Jobs Example" + +on: + push: + branches: [ main ] + workflow_dispatch: # Allow manual triggering + +jobs: + job2: + runs-on: ubuntu-latest + steps: + - name: StepA" + run: | + echo "World" + job1: + runs-on: ubuntu-latest + steps: + - name: StepB + run: + echo "Hello" \ No newline at end of file diff --git a/.github/workflows/workflow-command.yml b/.github/workflows/workflow-command.yml new file mode 100644 index 000000000..7d9824c27 --- /dev/null +++ b/.github/workflows/workflow-command.yml @@ -0,0 +1,22 @@ +name: "Workflow Commands" + +on: + push: + branches: [ main ] + +jobs: + my-job: + runs-on: ubuntu-latest + steps: + - name: "group logging" + run: | + echo "::group::My Group Message" + echo "Msg1" + echo "Msg2" + echo "::endgroup::" + - name: "step 1" + run: | + echo "MY_VAL=hello" >> "$GITHUB_ENV" + - name: "step 2" + run: | + echo "$MY_VAL" \ No newline at end of file diff --git a/github-actions/Readme.me b/github-actions/Readme.me index 9be613aad..1a74cc214 100644 --- a/github-actions/Readme.me +++ b/github-actions/Readme.me @@ -6,7 +6,7 @@ echo '{"name":"mona", "greeting":"hello"}' | gh workflow run greet.yml --json ``` ## Webhook Event - + ```sh curl -X POST \ -H "Accept: application/vnd.github+json" \ diff --git a/github-actions/mydata2 b/github-actions/mydata2 new file mode 100644 index 000000000..1bea4a2ee --- /dev/null +++ b/github-actions/mydata2 @@ -0,0 +1 @@ +SGVsbG8gTWFycw== \ No newline at end of file diff --git a/github-actions/templates/PostgreSQL image b/github-actions/templates/PostgreSQL image new file mode 100644 index 000000000..29e5b5d0f --- /dev/null +++ b/github-actions/templates/PostgreSQL image @@ -0,0 +1,34 @@ +# filepath: .github/workflows/postgres-image.yml +name: PostgreSQL Docker Workflow + +on: + push: + paths: + - 'docker/**' + - '.github/workflows/postgres-image.yml' + +jobs: + postgres: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: myuser + POSTGRES_PASSWORD: mypassword + POSTGRES_DB: mydatabase + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v4 + - name: Wait for PostgreSQL to be ready + run: | + for i in {1..30}; do + pg_isready -h localhost -p 5432 -U myuser && break + sleep 2 + done diff --git a/postgresql-workflow-example/.github/workflows/postgres-image.yml b/postgresql-workflow-example/.github/workflows/postgres-image.yml new file mode 100644 index 000000000..cf39e1bfb --- /dev/null +++ b/postgresql-workflow-example/.github/workflows/postgres-image.yml @@ -0,0 +1,36 @@ +name: Build and Push PostgreSQL Docker Image + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + # Ensure that DOCKER_USERNAME and DOCKER_PASSWORD are set in your repository's secrets at + # https://github.com///settings/secrets/actions + + - name: Build PostgreSQL Docker image + uses: docker/build-push-action@v2 + with: + context: ./docker + file: ./docker/Dockerfile + push: true + tags: your-dockerhub-username/postgres-image:latest + + - name: Logout from Docker Hub + run: docker logout \ No newline at end of file diff --git a/postgresql-workflow-example/README.md b/postgresql-workflow-example/README.md new file mode 100644 index 000000000..c06985253 --- /dev/null +++ b/postgresql-workflow-example/README.md @@ -0,0 +1,57 @@ +# PostgreSQL Workflow Example + +This project demonstrates how to build and push a PostgreSQL Docker image using GitHub Actions. It includes a Dockerfile for creating the PostgreSQL image and a GitHub Actions workflow for automating the build and push process. + +## Project Structure + +``` +postgresql-workflow-example +├── .github +│ └── workflows +│ └── postgres-image.yml # GitHub Actions workflow for building and pushing the Docker image +├── docker +│ └── Dockerfile # Dockerfile for PostgreSQL image +├── src +│ └── app.js # Main application file for connecting to the PostgreSQL database +├── package.json # npm configuration file +└── README.md # Project documentation +``` + +## Getting Started + +To get started with this project, follow these steps: + +1. **Clone the repository**: + ```bash + git clone + cd postgresql-workflow-example + ``` + +2. **Build the Docker image**: + Navigate to the `docker` directory and build the image using the Dockerfile: + ```bash + cd docker + docker build -t your-postgres-image-name . + ``` + +3. **Run the Docker container**: + After building the image, you can run it with: + ```bash + docker run --name your-container-name -e POSTGRES_PASSWORD=yourpassword -d your-postgres-image-name + ``` + +## GitHub Actions Workflow + +The GitHub Actions workflow defined in `.github/workflows/postgres-image.yml` automates the process of building and pushing the Docker image to a container registry whenever changes are pushed to the main branch. + +## Usage + +You can connect to the PostgreSQL database using the credentials specified in the Docker run command. The main application logic can be found in `src/app.js`, where you can implement your database operations. + +## Contributing + +Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes. + +## License + +This project is licensed under the MIT License. See the LICENSE file for more details. \ No newline at end of file diff --git a/postgresql-workflow-example/docker/Dockerfile b/postgresql-workflow-example/docker/Dockerfile new file mode 100644 index 000000000..c135da3d6 --- /dev/null +++ b/postgresql-workflow-example/docker/Dockerfile @@ -0,0 +1,9 @@ +FROM postgres:latest + +ENV POSTGRES_USER=myuser +ENV POSTGRES_PASSWORD=mypassword +ENV POSTGRES_DB=mydatabase + +COPY init.sql /docker-entrypoint-initdb.d/ + +EXPOSE 5432 \ No newline at end of file diff --git a/postgresql-workflow-example/package.json b/postgresql-workflow-example/package.json new file mode 100644 index 000000000..00f2de4de --- /dev/null +++ b/postgresql-workflow-example/package.json @@ -0,0 +1,27 @@ +{ + "name": "postgresql-workflow-example", + "version": "1.0.0", + "description": "A project to demonstrate building and pushing a PostgreSQL Docker image using GitHub Actions.", + "main": "src/app.js", + "scripts": { + "start": "node src/app.js", + "test": "echo \"No tests specified\" && exit 0" + }, + "dependencies": { + "pg": "^8.7.1" + }, + "devDependencies": { + "nodemon": "^2.0.15" + }, + "repository": { + "type": "git", + "url": "https://github.com/yourusername/postgresql-workflow-example.git" + }, + "keywords": [ + "postgresql", + "docker", + "github-actions" + ], + "author": "Your Name", + "license": "MIT" +} \ No newline at end of file diff --git a/postgresql-workflow-example/src/app.js b/postgresql-workflow-example/src/app.js new file mode 100644 index 000000000..e94ab239c --- /dev/null +++ b/postgresql-workflow-example/src/app.js @@ -0,0 +1,33 @@ +const express = require('express'); +const { Pool } = require('pg'); + +const app = express(); +const port = process.env.PORT || 3000; + +// PostgreSQL connection configuration +const pool = new Pool({ + user: process.env.DB_USER, + host: process.env.DB_HOST, + database: process.env.DB_NAME, + password: process.env.DB_PASSWORD, + port: process.env.DB_PORT, +}); + +// Middleware to parse JSON requests +app.use(express.json()); + +// Example route to get data from the database +app.get('/data', async (req, res) => { + try { + const result = await pool.query('SELECT * FROM your_table_name'); + res.status(200).json(result.rows); + } catch (err) { + console.error(err); + res.status(500).send('Server error'); + } +}); + +// Start the server +app.listen(port, () => { + console.log(`Server is running on port ${port}`); +}); \ No newline at end of file