From c279c2c475eb246d2c4e29ba35798d9a6c2f9278 Mon Sep 17 00:00:00 2001 From: Vasiliki Gkatziaki Date: Fri, 15 Nov 2024 15:09:54 +0100 Subject: [PATCH] Add Dockerfile and GitHub Actions workflow to automate building and pushing Docker image to GitHub Container Registry --- .github/workflows/docker-build.yaml | 40 +++++++++++++++++++++++++++++ docker/dockerfile | 11 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/workflows/docker-build.yaml create mode 100644 docker/dockerfile diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml new file mode 100644 index 0000000..b5192d4 --- /dev/null +++ b/.github/workflows/docker-build.yaml @@ -0,0 +1,40 @@ +name: Build and publish Docker image + +on: + push: + branches: [ main, staging ] + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4.2.2 + + - name: Log in to the Container registry + uses: docker/login-action@v3.3.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value={{sha}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6.9.0 + with: + push: true + file: docker/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/docker/dockerfile b/docker/dockerfile new file mode 100644 index 0000000..b152b3c --- /dev/null +++ b/docker/dockerfile @@ -0,0 +1,11 @@ +# Use the official Nginx image as the base image +FROM nginx:latest + +# Copy your static site files to the Nginx default directory +COPY ../dist /usr/share/nginx/html + +# Expose port 80 to allow traffic +EXPOSE 80 + +# Start Nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file