Skip to content

Commit 7342af1

Browse files
committed
docker image workflow
1 parent b435e48 commit 7342af1

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ignore target directory
2+
target/
3+
4+
# Ignore any build artifacts
5+
**/*.rs.bk
6+
7+
# Ignore any generated files
8+
**/Cargo.lock
9+
**/Cargo.toml.orig
10+
**/Cargo.toml.bk
11+
12+
# Ignore any IDE-specific files
13+
.vscode/
14+
.idea/
15+
16+
# Ignore Dockerfile and dockerignore file
17+
Dockerfile
18+
.dockerignore
19+
20+
# Workflow
21+
.github

.github/workflows/docker.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
7+
env:
8+
IMAGE_NAME: rusty
9+
10+
jobs:
11+
# Push image to GitHub Packages.
12+
# See also https://docs.docker.com/docker-hub/builds/
13+
build-linux:
14+
runs-on: ${{ matrix.config.os }}
15+
strategy:
16+
matrix:
17+
config:
18+
- {
19+
os: "ubuntu-latest",
20+
version: "linux",
21+
arch: "x86_64"
22+
}
23+
permissions:
24+
packages: write
25+
contents: read
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- name: Build image
31+
working-directory: ${{ matrix.config.version }}
32+
shell: bash
33+
run: docker buildx build . --platform ${{matrix.config.version}}/${{matrix.config.arch}} --file Dockerfile --tag $IMAGE_NAME
34+
35+
- name: Log in to registry
36+
if: ${{ github.event_name != 'pull_request' }}
37+
# This is where you will update the PAT to GITHUB_TOKEN
38+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
39+
40+
- name: Push image
41+
shell: bash
42+
if: ${{ github.event_name != 'pull_request' }}
43+
run: |
44+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
45+
46+
# Extract branch name
47+
BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
48+
49+
# Append branch name to image ID
50+
IMAGE_ID=$IMAGE_ID-$BRANCH_NAME
51+
52+
# Change all uppercase to lowercase
53+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
54+
55+
# Strip git ref prefix from version
56+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
57+
58+
# Use Docker `latest` tag convention
59+
[ "$VERSION" == "main" ] && VERSION=latest
60+
#Add the platform to the version
61+
VERSION=$VERSION-${{ matrix.config.arch }}
62+
echo IMAGE_ID=$IMAGE_ID
63+
echo VERSION=$VERSION
64+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
65+
docker push $IMAGE_ID:$VERSION

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# FROM mcr.microsoft.com/vscode/devcontainers/rust:latest
2+
FROM ghcr.io/plc-lang/rust-llvm:latest
3+
4+
# Avoid warnings by switching to noninteractive
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
8+
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
9+
# will be updated to match your local UID/GID (when using the dockerFile property).
10+
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
11+
# ARG USERNAME=vscode
12+
# ARG USER_UID=1000
13+
# ARG USER_GID=$USER_UID
14+
15+
# # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
16+
# RUN groupadd --gid $USER_GID $USERNAME \
17+
# && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
18+
# # [Optional] Add sudo support for the non-root user
19+
# && apt-get install -y sudo \
20+
# && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
21+
# && chmod 0440 /etc/sudoers.d/$USERNAME
22+
23+
# RUN apt-get -y update
24+
# RUN apt-get -y install git gdb docker.io
25+
26+
# RUN cargo install cargo-insta cargo-watch
27+
28+
# Give all users access to cargo and rust home
29+
RUN chmod -R a+rw $CARGO_HOME \
30+
&& chmod -R a+rw $RUSTUP_HOME
31+
32+
# Switch back to dialog for any ad-hoc use of apt-get
33+
ENV DEBIAN_FRONTEND=dialog
34+
ENV LLVM_VER=14
35+
36+
# Required if we want to use `lld` as the default linker for RuSTy
37+
RUN ln -sf /usr/bin/ld.lld-$LLVM_VER /usr/bin/ld.lld
38+
39+
# Install the local RuSTy version
40+
WORKDIR /rusty
41+
COPY . .
42+
RUN sed -i 's/build=0/build=1/' ./scripts/build.sh && \
43+
./scripts/build.sh
44+
45+
# Allow invoking `plc` from anywhere
46+
ENV PATH="/rusty/target/debug:${PATH}"
47+
48+
ENTRYPOINT [ "/bin/bash", "-c" ]
49+
CMD ["plc", "--help"]

0 commit comments

Comments
 (0)