diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..0bb3d22 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,44 @@ +name: Build and Publish Docker Image + +on: + push: + branches: + - master + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 # Check out your repository's code + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate build date + id: build_date + run: echo "::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + + - name: Build the Docker image + run: | + docker build \ + --file Dockerfile \ + --tag ghcr.io/${{ github.repository_owner }}/hammy-mchamiton:${{ github.run_number }} \ + --tag ghcr.io/${{ github.repository_owner }}/hammy-mchamilton:latest \ + --build-arg BUILD_DATE=${{ steps.build_date.outputs.BUILD_DATE }} \ + . + env: + BUILD_DATE: ${{ steps.build_date.outputs.BUILD_DATE }} + + - name: Push the Docker image to GitHub Container Registry + run: | + docker push ghcr.io/${{ github.repository_owner }}/hammy-mchamilton:${{ github.run_number }} + docker push ghcr.io/${{ github.repository_owner }}/hammy-mchamilton:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..52f6cc0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use official Python runtime as a parent image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install any needed dependencies specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Define environment variable +ENV PYTHONUNBUFFERED=1 + +# Add standard labels +LABEL maintainer="Joshua Clarke and Antony Bailey " +LABEL description="This is a Docker image for the Hammy McHamilton Discord Bot." +LABEL org.opencontainers.image.created="$BUILD_DATE" +# docker build --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -t hammy-mchamilton . + +# Run main.py when the container launches +CMD ["python", "main.py"]