Skip to content

Commit

Permalink
Add Dockerfile and add Github Action for building and pushing the ima…
Browse files Browse the repository at this point in the history
…ge to DockerHub
  • Loading branch information
Pezcraft committed May 13, 2024
1 parent 51ae952 commit e1b6b7f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,30 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Get Git Commit SHA
id: git_sha
run: echo "::set-output name=GIT_SHA::$(git rev-parse --short HEAD)"

- name: Build Docker image
run: docker image build -f Dockerfile -t pezcraft/my-firstimage:0.0.1 ./

- name: Set Docker tag
run: docker image tag pezcraft/my-firstimage:0.0.1 pezcraft/my-firstimage:${{ steps.git_sha.outputs.GIT_SHA }}

- name: Push Docker image to Docker Hub
run: docker image push pezcraft/my-firstimage:${{ steps.git_sha.outputs.GIT_SHA }}

22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.22.2-alpine

# Set maintainer label: maintainer=[YOUR-EMAIL]
LABEL maintainer="[email protected]"

# Set working directory: `/src`
WORKDIR /src

# Copy local file `main.go` to the working directory
COPY . .

# List items in the working directory (ls)
RUN ls

# Build the GO app as myapp binary and move it to /usr/
RUN go build -o /usr/myapp

#Expose port 8888
EXPOSE 8888

# Run the service myapp when a container of this image is launched
CMD ["/usr/myapp"]

0 comments on commit e1b6b7f

Please sign in to comment.